Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/CRUD/Users.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
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";
import {User} from "discord.js";

const cache = new LRUCache<SimpleUser['id'], SimpleUser>(1000);

const INVALID_USER_IDS = new Set<User['id']>();
class TTLSet<K> { // stop complaining about many things mr. musicmaker
#cache: TTLCache<K, null>; // 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<User['id']>();

export async function SaveUser(user: User | SimpleUser): Promise<void> {
const connection = await Database.getConnection();
Expand Down Expand Up @@ -72,4 +85,4 @@ export async function DiscardUser(id: string | bigint): Promise<void> {
export async function DANGER_PurgeUser(id: string | bigint): Promise<void> {
id = BigInt(id);
await Database.query('DELETE FROM Users WHERE id = ?', [id]);
}
}
Loading