Reduce redundant WHOISTHIS load
This commit is contained in:
parent
0a29264f53
commit
6e560d8bba
1 changed files with 5 additions and 3 deletions
|
@ -120,6 +120,7 @@ export default function Home() {
|
||||||
let Message = useRef<(message:MessageType) => React.ReactNode>(() => <></>);
|
let Message = useRef<(message:MessageType) => React.ReactNode>(() => <></>);
|
||||||
const [ affectedByUpdate, forceUpdate ] = useState({});
|
const [ affectedByUpdate, forceUpdate ] = useState({});
|
||||||
const externCachedUsers = useRef(new Map());
|
const externCachedUsers = useRef(new Map());
|
||||||
|
const externCacheRows = useRef(new Map());
|
||||||
/* END_SECT LHUA; */
|
/* END_SECT LHUA; */
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,8 +186,8 @@ export default function Home() {
|
||||||
user = usersRef.current.find(x => x.id == message.user);
|
user = usersRef.current.find(x => x.id == message.user);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
user = externCachedUsers.current.get(message.user);
|
user = externCachedUsers.current.get(message.user);
|
||||||
if (user == null) {
|
if (user == null && !externCacheRows.current.has(message.user)) {
|
||||||
new Promise((res, rej) => {
|
externCacheRows.current.set(message.user, new Promise((res, rej) => {
|
||||||
socket.emit('SIG_CHAT_WHOISTHIS', { id: message.user }, ({ type, spec, data }:Res) => {
|
socket.emit('SIG_CHAT_WHOISTHIS', { id: message.user }, ({ type, spec, data }:Res) => {
|
||||||
if (type.includes("ERR"))
|
if (type.includes("ERR"))
|
||||||
rej(`${type} - ${spec}`);
|
rej(`${type} - ${spec}`);
|
||||||
|
@ -195,8 +196,9 @@ export default function Home() {
|
||||||
res("");
|
res("");
|
||||||
forceUpdate({});
|
forceUpdate({});
|
||||||
}
|
}
|
||||||
|
externCacheRows.current.delete(message.user);
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
const canDelete = whoamiRef.current.admin || whoamiRef.current.id == message.user;
|
const canDelete = whoamiRef.current.admin || whoamiRef.current.id == message.user;
|
||||||
const timeSent = new Date(message.timestamp * 1000).toLocaleString();
|
const timeSent = new Date(message.timestamp * 1000).toLocaleString();
|
||||||
|
|
Loading…
Reference in a new issue