From 7fd36eaebcf10b3e4eab5409c43773bf26f49364 Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Mon, 13 Apr 2026 03:11:48 +0530 Subject: [PATCH] Optimize onboarding chat document creation with Promise.all (#822) --- .../onboarding/setup/chat-sidebar.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/web/components/onboarding/setup/chat-sidebar.tsx b/apps/web/components/onboarding/setup/chat-sidebar.tsx index 501c8fd6..022135d6 100644 --- a/apps/web/components/onboarding/setup/chat-sidebar.tsx +++ b/apps/web/components/onboarding/setup/chat-sidebar.tsx @@ -381,11 +381,9 @@ export function ChatSidebar({ formData }: ChatSidebarProps) { setIsLoading(true) try { - const documentIds: string[] = [] - - for (const draft of draftDocs) { + const promises = draftDocs.map(async (draft) => { if (draft.kind === "x_research" && xResearchStatus !== "correct") { - continue + return null } try { @@ -397,13 +395,17 @@ export function ChatSidebar({ formData }: ChatSidebarProps) { }, }) - if (docResponse.data?.id) { - documentIds.push(docResponse.data.id) - } + return docResponse.data?.id } catch (error) { console.warn("Error creating document:", error) + return null } - } + }) + + const results = await Promise.all(promises) + const documentIds = results.filter( + (id): id is string => id !== null && id !== undefined, + ) if (documentIds.length > 0) { await pollForMemories(documentIds)