fix: msghash性能问题

This commit is contained in:
手瓜一十雪
2024-07-30 23:06:58 +08:00
parent ebf90e72b9
commit bf5f548349
3 changed files with 20 additions and 20 deletions

View File

@@ -15,10 +15,10 @@ class LimitedHashTable<K, V> {
}
set(key: K, value: V): void {
const isExist = this.keyToValue.get(key);
if (isExist && isExist === value) {
return;
}
// const isExist = this.keyToValue.get(key);
// if (isExist && isExist === value) {
// return;
// }
this.keyToValue.set(key, value);
this.valueToKey.set(value, key);
while (this.keyToValue.size !== this.valueToKey.size) {
@@ -99,13 +99,13 @@ class MessageUniqueWrapper {
}
createMsg(peer: Peer, msgId: string): number | undefined {
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
const hash = crypto.createHash('sha1').update(key);
const shortId = Buffer.from(hash.digest('hex').slice(0, 8), 'hex').readInt32BE();
const isExist = this.msgIdMap.getKey(shortId);
//console.log(`${peer.peerUid} ${msgId} ------- ${shortId}`);
if (isExist && isExist === msgId) {
return shortId;
}
const hash = crypto.createHash('md5').update(key);
const shortId = hash.digest().readInt32BE(0);
//减少性能损耗
// const isExist = this.msgIdMap.getKey(shortId);
// if (isExist && isExist === msgId) {
// return shortId;
// }
this.msgIdMap.set(msgId, shortId);
this.msgDataMap.set(key, shortId);
return shortId;