From 8c999e45e9f85ba9e5705f98caca0d761028c1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?FAY=E3=82=B7?= <103030954+FAYStarNext@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:35:58 +0700 Subject: [PATCH 1/2] chore: Update search cache clearing in Manager.ts --- README.md | 10 ++++++++-- example/src/index.ts | 8 ++++++-- package.json | 2 +- src/structures/Manager.ts | 16 +++++----------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 9c93d9c..9a18712 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,7 @@ To install Sunday.ts, follow these steps: That's it! You have successfully installed Sunday.ts and are ready to start using it in your Node.js project. ## Features -- [ ] Multi version -- [ ] Plugin +- [x] SearchCache ## 🎈 Usage @@ -83,6 +82,10 @@ let manager = new Manager({ resumeStatus: true, }, ], + cache: { + enabled: true, + time: 60000, + }, clientId: "1234567890", send(guild_id, payload) { const guild = client.guilds.cache.get(guild_id); @@ -146,6 +149,9 @@ client.on("messageCreate", async (message) => { return message.reply(`enqueuing ${res.tracks[0].title}. ${end}`); } }); +manager.on("SearchCacheClear" , (key: string, values) => { + console.log(`Cache cleared for ${key} with values: ${values}`); +}); client.on("raw", (data) => manager.updateVoiceState(data)); client.on("ready" , () => { manager.init(client.user?.id as string); diff --git a/example/src/index.ts b/example/src/index.ts index f1377c9..9daa99c 100644 --- a/example/src/index.ts +++ b/example/src/index.ts @@ -20,6 +20,10 @@ let manager = new Manager({ resumeStatus: true, }, ], + cache: { + enabled: true, + time: 60000, + }, clientId: "1234567890", send(guild_id, payload) { const guild = client.guilds.cache.get(guild_id); @@ -83,8 +87,8 @@ client.on("messageCreate", async (message) => { return message.reply(`enqueuing ${res.tracks[0].title}. ${end}`); } }); -manager.on("SearchCacheClear" , (key: string, values) => { - console.log(`Cache cleared for ${key} with values: ${values}`); +manager.on("SearchCacheClear" , (data) => { + console.log(`Cache cleared: ${data}`); }); client.on("raw", (data) => manager.updateVoiceState(data)); client.on("ready" , () => { diff --git a/package.json b/package.json index 2b7776f..10e920e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "sunday.ts", "main": "dist/index.js", "types": "dist/index.d.ts", - "version": "1.0.11-indev", + "version": "1.0.12-indev", "description": "Sunday a lavalink wrapper", "license": "MIT", "author": "FAYStarNext", diff --git a/src/structures/Manager.ts b/src/structures/Manager.ts index edbcb0e..e34b02d 100644 --- a/src/structures/Manager.ts +++ b/src/structures/Manager.ts @@ -136,14 +136,8 @@ export class Manager extends TypedEmitter { if (this.options.nodes) this.options.nodes.forEach((nodeOptions) => { return new (Structure.get("Node"))(nodeOptions); }); setInterval(() => { - const searchCacheKeys = this.search_cache.keys(); - const searchCacheValues = this.search_cache.values(); - const firstKey = searchCacheKeys.next().value; - const firstValue = searchCacheValues.next().value; - if (firstKey && firstValue) { - const searchResultString = JSON.stringify(firstValue); - this.emit("SearchCacheClear", firstKey, searchResultString); - } + if (this.search_cache.clear() === undefined) return; + this.emit("SearchCacheClear", this.search_cache.values().next().value); this.search_cache.clear(); }, this.options.cache?.time || 10000); } @@ -240,7 +234,7 @@ export class Manager extends TypedEmitter { } } } - if (res.loadType === "search" || "track") this.search_cache.set(code, result); + if (options.cache !== false && this.options.cache.enabled !== false) if (res.loadType === "search" || "track") this.search_cache.set(code, result); return result; } catch (err) { throw new Error(err); @@ -445,7 +439,7 @@ export interface ManagerOptions { replaceYouTubeCredentials?: boolean; cache?: { /** Whether to enable cache. */ - enable: boolean; + enabled: boolean; /** Clear cache every second */ time: number; } @@ -506,7 +500,7 @@ export interface PlaylistData { } export interface ManagerEvents { - SearchCacheClear: (key: string, values: SearchResult | unknown) => void; + SearchCacheClear: (data: string) => void; NodeCreate: (node: Node) => void; NodeDestroy: (node: Node) => void; NodeConnect: (node: Node) => void; From ecafbefb77b6c8030c85cee9c38a55f1d9547c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?FAY=E3=82=B7?= <103030954+FAYStarNext@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:37:24 +0700 Subject: [PATCH 2/2] =?UTF-8?q?typescript-eslint=207.16.1=20=E2=86=92=207.?= =?UTF-8?q?17.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 10e920e..99284cf 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "devDependencies": { "@eslint/js": "^9.7.0", "@types/bun": "latest", - "eslint": "9.x", + "eslint": "^9.7.0", "globals": "^15.8.0", - "typescript-eslint": "^7.16.1", + "typescript-eslint": "^7.17.0", "@babel/cli": "^7.24.8", "@babel/core": "^7.24.9", "@babel/plugin-proposal-class-properties": "^7.18.6",