diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..baaba20c --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-18 - Optimize Stateful Sequential Iteration Over Network I/O +**Learning:** Sequential network calls inside a `for...of` loop can become a significant bottleneck when querying multiple endpoints or paths, especially when the calls are independent. +**Action:** Use `Promise.all` to fetch all resources concurrently. To preserve side-effect logic dependent on order (like keeping the "last" status or error), store the resolved promises in an array and iterate over them sequentially in the same order as the original paths array. diff --git a/src/lib/forge-openai-surface.ts b/src/lib/forge-openai-surface.ts index 93415262..afef3464 100644 --- a/src/lib/forge-openai-surface.ts +++ b/src/lib/forge-openai-surface.ts @@ -118,8 +118,13 @@ export async function collectZimaOSV1ModelEntries( let lastError: string | undefined; let lastRaw: unknown = null; - for (const path of V1_MODELS_PATHS) { - const r = await fetchZimaOSJson(email, path); + // ⚡ Bolt: Initiate all network requests concurrently to avoid sequential network delays. + // We don't await Promise.all so we process them individually as they arrive + // while preserving the original stateful fallback resolution logic. + const fetches = V1_MODELS_PATHS.map((path) => fetchZimaOSJson(email, path)); + + for (const p of fetches) { + const r = await p; lastStatus = r.status; lastError = r.error; lastRaw = r.data;