Skip to content

Commit 7fd36ea

Browse files
authored
Optimize onboarding chat document creation with Promise.all (#822)
1 parent a0e3d7d commit 7fd36ea

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

apps/web/components/onboarding/setup/chat-sidebar.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,9 @@ export function ChatSidebar({ formData }: ChatSidebarProps) {
381381
setIsLoading(true)
382382

383383
try {
384-
const documentIds: string[] = []
385-
386-
for (const draft of draftDocs) {
384+
const promises = draftDocs.map(async (draft) => {
387385
if (draft.kind === "x_research" && xResearchStatus !== "correct") {
388-
continue
386+
return null
389387
}
390388

391389
try {
@@ -397,13 +395,17 @@ export function ChatSidebar({ formData }: ChatSidebarProps) {
397395
},
398396
})
399397

400-
if (docResponse.data?.id) {
401-
documentIds.push(docResponse.data.id)
402-
}
398+
return docResponse.data?.id
403399
} catch (error) {
404400
console.warn("Error creating document:", error)
401+
return null
405402
}
406-
}
403+
})
404+
405+
const results = await Promise.all(promises)
406+
const documentIds = results.filter(
407+
(id): id is string => id !== null && id !== undefined,
408+
)
407409

408410
if (documentIds.length > 0) {
409411
await pollForMemories(documentIds)

0 commit comments

Comments
 (0)