Optimize onboarding chat document creation with Promise.all

This commit is contained in:
Ishaan Gupta 2026-04-02 10:18:32 +05:30
parent 1b40cedd23
commit 6567f3d84b

View file

@ -40,10 +40,6 @@ interface DraftDoc {
}
export function ChatSidebar({ formData }: ChatSidebarProps) {
const isValidDocId = (
id: string | null | undefined,
): id is string => !!id
const { user } = useAuth()
const { selectedProject } = useProject()
const isMobile = useIsMobile()
@ -385,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 {
@ -401,13 +395,17 @@ export function ChatSidebar({ formData }: ChatSidebarProps) {
},
})
if (isValidDocId(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)