From 5a35ab6c34b8ab9618a32efc9b4a05c4ffb8edca Mon Sep 17 00:00:00 2001 From: po-lan <42771836+po-lan@users.noreply.github.com> Date: Tue, 28 May 2024 22:26:02 +0800 Subject: [PATCH 1/5] Update OB11GroupIncreaseEvent.ts --- src/onebot11/event/notice/OB11GroupIncreaseEvent.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/onebot11/event/notice/OB11GroupIncreaseEvent.ts b/src/onebot11/event/notice/OB11GroupIncreaseEvent.ts index 7e875d50..99f891e8 100644 --- a/src/onebot11/event/notice/OB11GroupIncreaseEvent.ts +++ b/src/onebot11/event/notice/OB11GroupIncreaseEvent.ts @@ -1,5 +1,6 @@ import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent'; import { dbUtil } from '@/common/utils/db'; +import { ob11Config } from '@/onebot11/config'; type GroupIncreaseSubType = 'approve' | 'invite'; export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent { @@ -13,7 +14,8 @@ export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent { this.user_id = userId; this.sub_type = subType; - dbUtil.insertJoinTime(groupId, userId, Math.floor(Date.now() / 1000)) + if((ob11Config.GroupLocalTimeRecord[0] == -1 || ob11Config.GroupLocalTimeRecord.includes(groupId))) + dbUtil.insertJoinTime(groupId, userId, Math.floor(Date.now() / 1000)) } } From 66d60d35995863b1343c89b984095e034efc9bd6 Mon Sep 17 00:00:00 2001 From: po-lan <42771836+po-lan@users.noreply.github.com> Date: Tue, 28 May 2024 22:27:12 +0800 Subject: [PATCH 2/5] Update main.ts --- src/onebot11/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index edcb114d..2acd7f8f 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -286,7 +286,7 @@ export class NapCatOnebot11 { } if (msg.post_type === 'message') { logMessage(msg as OB11Message).then().catch(logError); - if (msg.message_type == 'group' && msg.group_id && (ob11Config.GroupLocalTimeRecord as Array).find((item) => item == msg.group_id)) { + if (msg.message_type == 'group' && msg.group_id && (ob11Config.GroupLocalTimeRecord[0] === -1 || ob11Config.GroupLocalTimeRecord.includes(msg.group_id))) { dbUtil.insertLastSentTime(msg.group_id, msg.user_id, msg.time); } } else if (msg.post_type === 'notice') { From 16f926401b9135db7aa0863cc6b0e5bad50ca05c Mon Sep 17 00:00:00 2001 From: po-lan <42771836+po-lan@users.noreply.github.com> Date: Tue, 28 May 2024 22:30:26 +0800 Subject: [PATCH 3/5] Update db.ts --- src/common/utils/db.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/common/utils/db.ts b/src/common/utils/db.ts index 01df04ff..a200089d 100644 --- a/src/common/utils/db.ts +++ b/src/common/utils/db.ts @@ -484,27 +484,25 @@ class DBUtil extends DBUtilBase { userId: number, time: number ) { - if (ob11Config.GroupLocalTimeRecord[0] == -1 || ob11Config.GroupLocalTimeRecord.includes(groupId)) - this.LURCache.set(groupId, userId, time) + this.LURCache.set(groupId, userId, time) } async insertJoinTime( groupId: number, userId: number, time: number ) { - if (ob11Config.GroupLocalTimeRecord[0] == -1 || ob11Config.GroupLocalTimeRecord.includes(groupId)){ - await this.createGroupInfoTimeTableIfNotExist(groupId); - this.db!.all( - `INSERT OR REPLACE INTO "${groupId}" (user_id, last_sent_time, join_time) VALUES (?,?,?)`, - [userId, time, time], - (err) => { - if (err) - logError(err), - Promise.reject(), - console.log("插入入群时间失败", userId, groupId); - } - ); - } + await this.createGroupInfoTimeTableIfNotExist(groupId); + this.db!.all( + `INSERT OR REPLACE INTO "${groupId}" (user_id, last_sent_time, join_time) VALUES (?,?,?)`, + [userId, time, time], + (err) => { + if (err) + logError(err), + Promise.reject(), + console.log("插入入群时间失败", userId, groupId); + } + ); + } } From 32d26248dc97e520506d419d9e38a7bfbd911afb Mon Sep 17 00:00:00 2001 From: po-lan <42771836+po-lan@users.noreply.github.com> Date: Tue, 28 May 2024 22:41:40 +0800 Subject: [PATCH 4/5] Update main.ts --- src/onebot11/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index 2acd7f8f..2d65d34b 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -286,7 +286,8 @@ export class NapCatOnebot11 { } if (msg.post_type === 'message') { logMessage(msg as OB11Message).then().catch(logError); - if (msg.message_type == 'group' && msg.group_id && (ob11Config.GroupLocalTimeRecord[0] === -1 || ob11Config.GroupLocalTimeRecord.includes(msg.group_id))) { + // 大概测试了一下,2700个以内,find的性能更好 + if (msg.message_type == 'group' && msg.group_id && (ob11Config.GroupLocalTimeRecord[0] === -1 || ob11Config.GroupLocalTimeRecord.find(gid=>gid == msg.group_id))) { dbUtil.insertLastSentTime(msg.group_id, msg.user_id, msg.time); } } else if (msg.post_type === 'notice') { From 8f2676ec199ae15afce7a06565589fac6da18235 Mon Sep 17 00:00:00 2001 From: po-lan <42771836+po-lan@users.noreply.github.com> Date: Tue, 28 May 2024 22:43:41 +0800 Subject: [PATCH 5/5] Update main.ts --- src/onebot11/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index 2d65d34b..d135cffa 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -286,7 +286,7 @@ export class NapCatOnebot11 { } if (msg.post_type === 'message') { logMessage(msg as OB11Message).then().catch(logError); - // 大概测试了一下,2700个以内,find的性能更好 + // 大概测试了一下,10000个以内 includes 和 find 性能差距不大 if (msg.message_type == 'group' && msg.group_id && (ob11Config.GroupLocalTimeRecord[0] === -1 || ob11Config.GroupLocalTimeRecord.find(gid=>gid == msg.group_id))) { dbUtil.insertLastSentTime(msg.group_id, msg.user_id, msg.time); }