mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 13:22:41 +02:00
feat: implement map and find optimization
This commit is contained in:
parent
b1631cd6f1
commit
03a24686fe
3 changed files with 11 additions and 6 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue