From 6e560d8bbabd876ec0dd59e935bc937634f4788e Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Thu, 9 May 2024 19:25:16 -0500 Subject: [PATCH] Reduce redundant WHOISTHIS load --- src/app/chat/page.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/chat/page.tsx b/src/app/chat/page.tsx index 0903528..0f2fbe7 100644 --- a/src/app/chat/page.tsx +++ b/src/app/chat/page.tsx @@ -120,6 +120,7 @@ export default function Home() { let Message = useRef<(message:MessageType) => React.ReactNode>(() => <>); const [ affectedByUpdate, forceUpdate ] = useState({}); const externCachedUsers = useRef(new Map()); + const externCacheRows = useRef(new Map()); /* END_SECT LHUA; */ @@ -185,8 +186,8 @@ export default function Home() { user = usersRef.current.find(x => x.id == message.user); if (user == null) user = externCachedUsers.current.get(message.user); - if (user == null) { - new Promise((res, rej) => { + if (user == null && !externCacheRows.current.has(message.user)) { + externCacheRows.current.set(message.user, new Promise((res, rej) => { socket.emit('SIG_CHAT_WHOISTHIS', { id: message.user }, ({ type, spec, data }:Res) => { if (type.includes("ERR")) rej(`${type} - ${spec}`); @@ -195,8 +196,9 @@ export default function Home() { res(""); forceUpdate({}); } + externCacheRows.current.delete(message.user); }); - }); + })); } const canDelete = whoamiRef.current.admin || whoamiRef.current.id == message.user; const timeSent = new Date(message.timestamp * 1000).toLocaleString();