From 669231e8a68df4337e4516cd9ed3ba2c9d068e71 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 14:57:08 -0500 Subject: [PATCH] actually load from cache --- index.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index c9fa8eb..cbbf791 100755 --- a/index.js +++ b/index.js @@ -89,7 +89,7 @@ async function updateSongs() { // For each song that youtube moosic has yelled back at us, give them individually to populateThumbnails() await Promise.all(playlistSongs.map(async song => await populateThumbnails(song))); // Write all of this to cache - fs.writeFileSync(path.join(baseDir + 'ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails})); + fs.writeFileSync(path.join(baseDir + '/ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails})); } else { // like legit this shouldnt even be possible @@ -298,15 +298,25 @@ async function customConsole() { } } -// Wrap in a async function to wait for youtube music response before starting http server -// (to prevent a race condition where people can view the moosic page be4 it is ready) async function main() { - // Init the moosics stuff (black magic) - await ytmusic.initialize(); + // Load from cache + await (async () => { + let cachefile; + cachefile = fs.readFileSync(path.join(baseDir, '/ytmusic_cache')); + let parsed_cachefile = JSON.parse(cachefile); + playlistSongs = parsed_cachefile.playlistSongs; + thumbnails = parsed_cachefile.thumbnails; + }); - // Populate playlistSongs and thumbnails - await updateSongs(); + // Wrap in async but don't await as to not delay server boot, we can load from cache faster then we can load from yt music + (async () => { + // Init the moosics stuff + await ytmusic.initialize(); + + // Populate playlistSongs and thumbnails + await updateSongs(); + }); // Populate the blog index await generateBlogIndex(); @@ -319,11 +329,11 @@ async function main() { // Start hourly loop to update playlist loopHourly(async () => await updateSongs()); + + // Start console + customConsole(); }); })(); - - // Start console - customConsole(); } // Handle a few signals