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 {
|
||||
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;
|
||||
|
@ -151,7 +151,7 @@ export class NTQQMsgApi {
|
||||
}
|
||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||
let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime());
|
||||
//console.log(msgId);
|
||||
console.log(msgId);
|
||||
let data = await NTEventDispatch.CallNormalEvent<
|
||||
(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map<any, any>) => Promise<unknown>,
|
||||
(msgList: RawMessage[]) => void
|
||||
@ -161,14 +161,14 @@ export class NTQQMsgApi {
|
||||
1,
|
||||
timeout,
|
||||
(msgRecords: RawMessage[]) => {
|
||||
for (let msgRecord of msgRecords) {
|
||||
if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// for (let msgRecord of msgRecords) {
|
||||
// if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
return true;
|
||||
},
|
||||
msgId,
|
||||
"0",
|
||||
peer,
|
||||
msgElements,
|
||||
new Map()
|
||||
|
@ -170,7 +170,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
// log("send msg:", peer, sendElements)
|
||||
|
||||
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);
|
||||
return { message_id: returnMsg!.id! };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user