mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: msghash性能问题
This commit is contained in:
parent
ebf90e72b9
commit
bf5f548349
@ -15,10 +15,10 @@ class LimitedHashTable<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set(key: K, value: V): void {
|
set(key: K, value: V): void {
|
||||||
const isExist = this.keyToValue.get(key);
|
// const isExist = this.keyToValue.get(key);
|
||||||
if (isExist && isExist === value) {
|
// if (isExist && isExist === value) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
this.keyToValue.set(key, value);
|
this.keyToValue.set(key, value);
|
||||||
this.valueToKey.set(value, key);
|
this.valueToKey.set(value, key);
|
||||||
while (this.keyToValue.size !== this.valueToKey.size) {
|
while (this.keyToValue.size !== this.valueToKey.size) {
|
||||||
@ -99,13 +99,13 @@ class MessageUniqueWrapper {
|
|||||||
}
|
}
|
||||||
createMsg(peer: Peer, msgId: string): number | undefined {
|
createMsg(peer: Peer, msgId: string): number | undefined {
|
||||||
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
|
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
|
||||||
const hash = crypto.createHash('sha1').update(key);
|
const hash = crypto.createHash('md5').update(key);
|
||||||
const shortId = Buffer.from(hash.digest('hex').slice(0, 8), 'hex').readInt32BE();
|
const shortId = hash.digest().readInt32BE(0);
|
||||||
const isExist = this.msgIdMap.getKey(shortId);
|
//减少性能损耗
|
||||||
//console.log(`${peer.peerUid} ${msgId} ------- ${shortId}`);
|
// const isExist = this.msgIdMap.getKey(shortId);
|
||||||
if (isExist && isExist === msgId) {
|
// if (isExist && isExist === msgId) {
|
||||||
return shortId;
|
// return shortId;
|
||||||
}
|
// }
|
||||||
this.msgIdMap.set(msgId, shortId);
|
this.msgIdMap.set(msgId, shortId);
|
||||||
this.msgDataMap.set(key, shortId);
|
this.msgDataMap.set(key, shortId);
|
||||||
return shortId;
|
return shortId;
|
||||||
|
@ -151,7 +151,7 @@ export class NTQQMsgApi {
|
|||||||
}
|
}
|
||||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||||
let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime());
|
let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime());
|
||||||
//console.log(msgId);
|
console.log(msgId);
|
||||||
let data = await NTEventDispatch.CallNormalEvent<
|
let data = await NTEventDispatch.CallNormalEvent<
|
||||||
(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map<any, any>) => Promise<unknown>,
|
(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map<any, any>) => Promise<unknown>,
|
||||||
(msgList: RawMessage[]) => void
|
(msgList: RawMessage[]) => void
|
||||||
@ -161,14 +161,14 @@ export class NTQQMsgApi {
|
|||||||
1,
|
1,
|
||||||
timeout,
|
timeout,
|
||||||
(msgRecords: RawMessage[]) => {
|
(msgRecords: RawMessage[]) => {
|
||||||
for (let msgRecord of msgRecords) {
|
// for (let msgRecord of msgRecords) {
|
||||||
if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) {
|
// if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
return true;
|
||||||
},
|
},
|
||||||
msgId,
|
"0",
|
||||||
peer,
|
peer,
|
||||||
msgElements,
|
msgElements,
|
||||||
new Map()
|
new Map()
|
||||||
|
@ -170,7 +170,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
// log("send msg:", peer, sendElements)
|
// log("send msg:", peer, sendElements)
|
||||||
|
|
||||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(messages, group);
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(messages, group);
|
||||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
console.log(peer, JSON.stringify(sendElements,null,2));
|
||||||
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles);
|
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles);
|
||||||
return { message_id: returnMsg!.id! };
|
return { message_id: returnMsg!.id! };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user