refactor: msgId stage-2

This commit is contained in:
手瓜一十雪
2024-07-22 11:34:18 +08:00
parent 4f9fb2c8c3
commit 087c76b394
9 changed files with 22 additions and 31 deletions

View File

@@ -57,9 +57,11 @@ class LimitedHashTable<K, V> {
}
class MessageUniqueWrapper {
private msgDataMap: LimitedHashTable<string, number>;
private msgIdMap: LimitedHashTable<string, number>;
constructor(maxMap: number = 1000) {
this.msgIdMap = new LimitedHashTable<string, number>(maxMap);
this.msgDataMap = new LimitedHashTable<string, number>(maxMap);
}
createMsg(peer: Peer, msgId: string): number | undefined {
@@ -70,8 +72,8 @@ class MessageUniqueWrapper {
if (isExist && isExist === msgId) {
return undefined;
}
this.msgIdMap.set(key, shortId);
this.msgIdMap.set(msgId, shortId);
this.msgDataMap.set(key, shortId);
return shortId;
}
@@ -92,6 +94,11 @@ class MessageUniqueWrapper {
getShortIdByMsgId(msgId: string): number | undefined {
return this.msgIdMap.getValue(msgId);
}
getPeerByMsgId(msgId: string) {
const shortId = this.msgIdMap.getValue(msgId);
if (!shortId) return undefined;
return this.getMsgIdAndPeerByShortId(shortId);
}
}
export const MessageUnique = new MessageUniqueWrapper(1000);