|
|
|
|
@ -3,7 +3,7 @@ import { db } from '../db';
|
|
|
|
|
const env = process.env;
|
|
|
|
|
|
|
|
|
|
// In-memory cache for active groups
|
|
|
|
|
const activeGroupsCache = new Map<string, string>(); // groupId -> groupName
|
|
|
|
|
// const activeGroupsCache = new Map<string, string>(); // groupId -> groupName
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents a group from the Evolution API response
|
|
|
|
|
@ -36,6 +36,9 @@ export class GroupSyncService {
|
|
|
|
|
// Static property for DB instance injection (defaults to global db)
|
|
|
|
|
static dbInstance: Database = db;
|
|
|
|
|
|
|
|
|
|
// In-memory cache for active groups (made public for tests)
|
|
|
|
|
public static readonly activeGroupsCache = new Map<string, string>(); // groupId -> groupName
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the sync interval duration in milliseconds.
|
|
|
|
|
*
|
|
|
|
|
@ -199,11 +202,11 @@ export class GroupSyncService {
|
|
|
|
|
|
|
|
|
|
private static cacheActiveGroups(): void {
|
|
|
|
|
const groups = this.dbInstance.prepare('SELECT id, name FROM groups WHERE active = TRUE').all();
|
|
|
|
|
activeGroupsCache.clear();
|
|
|
|
|
this.activeGroupsCache.clear();
|
|
|
|
|
for (const group of groups) {
|
|
|
|
|
activeGroupsCache.set(group.id, group.name);
|
|
|
|
|
this.activeGroupsCache.set(group.id, group.name);
|
|
|
|
|
}
|
|
|
|
|
console.log(`Cached ${activeGroupsCache.size} active groups`);
|
|
|
|
|
console.log(`Cached ${this.activeGroupsCache.size} active groups`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static getActiveGroupsCount(): number {
|
|
|
|
|
@ -330,6 +333,6 @@ export class GroupSyncService {
|
|
|
|
|
* @returns True if the group is active, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static isGroupActive(groupId: string): boolean {
|
|
|
|
|
return activeGroupsCache.has(groupId);
|
|
|
|
|
return this.activeGroupsCache.has(groupId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|