From 1add4d4ace75ddd27cce41478ede5407ae4c23f2 Mon Sep 17 00:00:00 2001 From: Calemy <45440100+Calemy@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:15:33 +0000 Subject: [PATCH] qol: implement lock mechanic --- modules/cron.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/cron.js b/modules/cron.js index 3d7dc30..0cee49f 100644 --- a/modules/cron.js +++ b/modules/cron.js @@ -10,8 +10,12 @@ const logger = new Logger().addTimestamp("hh:mm:ss").changeTag("Fetch").purple() const stats = await database.awaitQuery(`SELECT user, playcount, time, mode FROM (SELECT user, playcount, time, mode, ROW_NUMBER() OVER (PARTITION BY user, mode ORDER BY time DESC) AS rn FROM stats_${new Date().getFullYear()} s, users u WHERE s.user = u.userid AND u.available = 1) AS ranked WHERE rn = 1`) fillCache(stats); +let locked = false; + function update(){ + if(locked) return; return new Promise(async (resolve) => { + locked = true; const users = await database.awaitQuery(`SELECT userid id, username FROM users WHERE available = 1`) logger.send(`Updating ${users.length} Users`) for(let i = 0; i < users.length; i += 50){ @@ -37,6 +41,7 @@ function update(){ updated.stats = 0; updated.scores = 0; logger.send("Finished update.") + locked = false; return resolve() }) }