diff --git a/src/CRUD/Users.ts b/src/CRUD/Users.ts index c0af824..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"; @@ -6,7 +7,19 @@ import {User} from "discord.js"; const cache = new LRUCache(1000); -const INVALID_USER_IDS = new Set(); +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(); @@ -72,4 +85,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 +}