mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-10 22:41:17 +00:00
Optimize onboarding chat document creation with Promise.all
This commit is contained in:
parent
1b40cedd23
commit
6567f3d84b
1 changed files with 10 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue