mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
commit
70df6e3302
@ -1,4 +1,4 @@
|
||||
import { logError, logDebug } from '@/common/utils/log';
|
||||
import { logError, logDebug } from "@/common/utils/log";
|
||||
|
||||
type group_id = number;
|
||||
type user_id = number;
|
||||
@ -31,7 +31,7 @@ class LRU<T> {
|
||||
private tail: cacheNode<T> | null = null;
|
||||
private onFuncs: ((node: cacheNode<T>) => void)[] = [];
|
||||
|
||||
constructor(maxAge: number = 2e4, maxSize: number = 5e3) {
|
||||
constructor(maxAge: number = 6e4, maxSize: number = 5e3) {
|
||||
this.maxAge = maxAge;
|
||||
this.maxSize = maxSize;
|
||||
this.cache = Object.create(null);
|
||||
@ -44,7 +44,7 @@ class LRU<T> {
|
||||
// 移除LRU节点
|
||||
private removeLRUNode(node: cacheNode<T>) {
|
||||
logDebug(
|
||||
'removeLRUNode',
|
||||
"removeLRUNode",
|
||||
node.groupId,
|
||||
node.userId,
|
||||
node.value,
|
||||
@ -140,6 +140,26 @@ class LRU<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
public get(groupId: group_id): { userId: user_id; value: T }[];
|
||||
public get(groupId: group_id, userId: user_id): null | { userId: user_id; value: T };
|
||||
public get(groupId: group_id, userId?: user_id): any {
|
||||
const groupObject = this.cache[groupId];
|
||||
if(!groupObject) return userId === undefined ? [] : null;
|
||||
|
||||
if (userId === undefined) {
|
||||
return Object.entries(groupObject).map(([userId, { value }]) => ({
|
||||
userId: Number(userId),
|
||||
value,
|
||||
}));
|
||||
}
|
||||
|
||||
if (groupObject[userId]) {
|
||||
return { userId, value: groupObject[userId].value };
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default LRU;
|
||||
|
@ -408,10 +408,12 @@ class DBUtil extends DBUtilBase {
|
||||
logDebug('读取发言时间', groupId);
|
||||
return new Promise<IRember[]>((resolve, reject) => {
|
||||
this.db!.all(`SELECT * FROM "${groupId}" `, (err, rows: IRember[]) => {
|
||||
const cache = this.LURCache.get(groupId).map(e=>({user_id:e.userId, last_sent_time:e.value}));
|
||||
if (err) {
|
||||
logError('查询发言时间失败', groupId);
|
||||
return resolve([]);
|
||||
return resolve(cache.map(e=>({...e, join_time:0})));
|
||||
}
|
||||
Object.assign(rows, cache)
|
||||
logDebug('查询发言时间成功', groupId, rows);
|
||||
resolve(rows);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user