From: Benjamin Auder Date: Fri, 7 Feb 2020 12:39:12 +0000 (+0100) Subject: Fix CRON tasks X-Git-Url: https://git.auder.net/%7B%7B%20path%28%27mixstore_static_policy%27%29%20%7D%7D?a=commitdiff_plain;h=cf7fac89918e50d8c93f9a09842c9eb53e8841d6;p=vchess.git Fix CRON tasks --- diff --git a/server/models/Challenge.js b/server/models/Challenge.js index fa0407dc..7ccaa76f 100644 --- a/server/models/Challenge.js +++ b/server/models/Challenge.js @@ -104,14 +104,14 @@ const ChallengeModel = const day = 86400000; db.serialize(function() { const query = - "SELECT id, target " + + "SELECT id, target, added " + "FROM Challenges"; db.all(query, (err, challenges) => { challenges.forEach(c => { if ((!c.target && tsNow - c.added > 30*day) || (!!c.target && tsNow - c.added > 2*day)) { - db.run("DELETE FROM CHallenges WHERE id = " + c.id); + db.run("DELETE FROM Challenges WHERE id = " + c.id); } }); }); diff --git a/server/models/Game.js b/server/models/Game.js index d57aac8d..79bf071f 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -268,7 +268,7 @@ const GameModel = const day = 86400000; db.serialize(function() { let query = - "SELECT id,score " + + "SELECT id,score,created " + "FROM Games "; db.all(query, (err,games) => { games.forEach(g => { @@ -277,13 +277,19 @@ const GameModel = "FROM Moves " + "WHERE gid = " + g.id; db.get(query, (err2,updated) => { - if (!updated && tsNow - g.created > 7*day) - return GameModel.remove(g.id); - const lastMaj = updated.lastMaj; - if (g.score != "*" && tsNow - lastMaj > 7*day || - g.score == "*" && tsNow - lastMaj > 91*day) + if (!updated.lastMaj) { - GameModel.remove(g.id); + if (tsNow - g.created > 7*day) + return GameModel.remove(g.id); + } + else //at least one move + { + const lastMaj = updated.lastMaj; + if (g.score != "*" && tsNow - lastMaj > 7*day || + g.score == "*" && tsNow - lastMaj > 91*day) + { + GameModel.remove(g.id); + } } }); });