From 81d63f9de3b542a1f0218548d112cad39579b194 Mon Sep 17 00:00:00 2001 From: Devyxi Date: Sun, 16 Aug 2026 09:29:44 +0100 Subject: [PATCH 1/3] Replace Set with TTLCache for invalid user IDs --- src/CRUD/Users.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CRUD/Users.ts b/src/CRUD/Users.ts index c0af824..dabdbcd 100644 --- a/src/CRUD/Users.ts +++ b/src/CRUD/Users.ts @@ -6,7 +6,8 @@ import {User} from "discord.js"; const cache = new LRUCache(1000); -const INVALID_USER_IDS = new Set(); +import { TTLCache } from "../Utils/DataStructures/TTLCache.js"; +const INVALID_USER_IDS = new TTLCache(); export async function SaveUser(user: User | SimpleUser): Promise { const connection = await Database.getConnection(); @@ -46,7 +47,7 @@ export async function GetUser(id: string | bigint): Promise null) if (!fetched) { - INVALID_USER_IDS.add(stringID); + INVALID_USER_IDS.set(stringID, true); return null; } @@ -72,4 +73,4 @@ export async function DiscardUser(id: string | bigint): Promise { export async function DANGER_PurgeUser(id: string | bigint): Promise { id = BigInt(id); await Database.query('DELETE FROM Users WHERE id = ?', [id]); -} \ No newline at end of file +} From 5ca40526b8921ff2cb807c70fa43ff04091560de Mon Sep 17 00:00:00 2001 From: Devyxi Date: Sun, 16 Aug 2026 09:36:00 +0100 Subject: [PATCH 2/3] Refactor invalid user ID management to use TTLSet Replaced TTLCache with TTLSet for managing invalid user IDs. --- src/CRUD/Users.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/CRUD/Users.ts b/src/CRUD/Users.ts index dabdbcd..b105e47 100644 --- a/src/CRUD/Users.ts +++ b/src/CRUD/Users.ts @@ -6,8 +6,19 @@ import {User} from "discord.js"; const cache = new LRUCache(1000); -import { TTLCache } from "../Utils/DataStructures/TTLCache.js"; -const INVALID_USER_IDS = new TTLCache(); +class TTLSet { // stop complaining about many things mr. musicmaker + #cache: TTLCache; // lets be big-brain here cuz we gotta lock in + + constructor(ttl?: number) { + this.#cache = new TTLCache(ttl); + } + + add(key: K): void { this.#cache.set(key, null); } + has(key: K): boolean { return this.#cache.has(key); } + delete(key: K): void { this.#cache.delete(key); } +} + +const INVALID_USER_IDS = new TTLSet(); export async function SaveUser(user: User | SimpleUser): Promise { const connection = await Database.getConnection(); From c17c0ad69ff37338e0249c860459050c9aa11905 Mon Sep 17 00:00:00 2001 From: Devyxi Date: Sun, 16 Aug 2026 09:39:22 +0100 Subject: [PATCH 3/3] Change INVALID_USER_IDS to use Set for user IDs --- src/CRUD/Users.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CRUD/Users.ts b/src/CRUD/Users.ts index b105e47..4bbc4da 100644 --- a/src/CRUD/Users.ts +++ b/src/CRUD/Users.ts @@ -1,4 +1,5 @@ import {LRUCache} from "../Utils/DataStructures/LRUCache.js"; +import {TTLCache} from "../Utils/DataStructures/TTLCache.js"; import {client} from "../Client.js"; import {Database} from "../Database.js"; import {SimpleUser} from "../Typings/DatabaseTypes.js"; @@ -58,7 +59,7 @@ export async function GetUser(id: string | bigint): Promise null) if (!fetched) { - INVALID_USER_IDS.set(stringID, true); + INVALID_USER_IDS.add(stringID); return null; }