diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index a594b740d..f80b3a87f 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -228,13 +228,14 @@ export default function NewChatPage() { return prev; } + const memberById = new Map(membersData?.map((m) => [m.user_id, m]) ?? []); + const prevById = new Map(prev.map((m) => [m.id, m])); + return syncedMessages.map((msg) => { - const member = msg.author_id - ? membersData?.find((m) => m.user_id === msg.author_id) - : null; + const member = msg.author_id ? memberById.get(msg.author_id) ?? null : null; // Preserve existing author info if member lookup fails (e.g., cloned chats) - const existingMsg = prev.find((m) => m.id === `msg-${msg.id}`); + const existingMsg = prevById.get(`msg-${msg.id}`); const existingAuthor = existingMsg?.metadata?.custom?.author as | { displayName?: string | null; avatarUrl?: string | null } | undefined; diff --git a/surfsense_web/hooks/use-documents.ts b/surfsense_web/hooks/use-documents.ts index df782ca83..b01adc10a 100644 --- a/surfsense_web/hooks/use-documents.ts +++ b/surfsense_web/hooks/use-documents.ts @@ -246,9 +246,11 @@ export function useDocuments( status: (doc.status as unknown as DocumentStatusType) ?? { state: "ready" }, })); + const liveById = new Map(validItems.map((v) => [v.id, v])); + let updated = prev.map((existing) => { if (liveIds.has(existing.id)) { - const liveItem = validItems.find((v) => v.id === existing.id); + const liveItem = liveById.get(existing.id); if (liveItem) { return { ...existing, diff --git a/surfsense_web/hooks/use-inbox.ts b/surfsense_web/hooks/use-inbox.ts index 4203c3506..e1070219a 100644 --- a/surfsense_web/hooks/use-inbox.ts +++ b/surfsense_web/hooks/use-inbox.ts @@ -157,8 +157,10 @@ export function useInbox( }) as InboxItem ); + const liveById = new Map(recentItems.map((v) => [v.id, v])); + let updated = prev.map((existing) => { - const liveItem = recentItems.find((v) => v.id === existing.id); + const liveItem = liveById.get(existing.id); if (liveItem) { return { ...existing,