From bf0d511282a95904b2253b7797378a5a0457b27e Mon Sep 17 00:00:00 2001 From: Ruthenic Date: Sun, 29 Jan 2023 06:46:00 -0500 Subject: [PATCH] make caching sane --- wattpad.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/wattpad.ts b/wattpad.ts index 511deab..d02ca33 100644 --- a/wattpad.ts +++ b/wattpad.ts @@ -17,23 +17,14 @@ const cache: { }; } = {}; -// re-init oldest story in cache every 5 minutes +// delete oldest story in cache every 5 minutes as to not memory leak to hell and back setInterval(() => { const oldStory = Object.values(cache).sort((a, b) => // @ts-expect-error 2363; javascript is a disgrace but it makes sorting dates easy so ¯\_(ツ)_/¯ b.timestamp - a.timestamp ).pop(); // teehee if (!oldStory) return; - cache[oldStory.story.id].timestamp = new Date(); - cache[oldStory.story.id].story.init().then(async (_) => { - for ( - let i = 0; - i < cache[oldStory.story.id].story.chapters.length; - i++ - ) { - await cache[oldStory.story.id].story.chapters[i].init(); - } - }); + delete cache[oldStory.story.id]; }, 300000); export { watt };