X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=9d700826364b02690df117d06ed569f710dca652;hb=f854c94f5ba65f1797fd803416e53f057f29f151;hp=16c050cd02cf8677238128072fdda3c6dd92230c;hpb=714680114508183fba2c07231dbe8f90b5631b81;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 16c050cd..9d700826 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -36,8 +36,6 @@ const GameModel = checkGameInfo: function(g) { if (!g.vid.toString().match(/^[0-9]+$/)) return "Wrong variant ID"; - if (!g.vname.match(/^[a-zA-Z0-9]+$/)) - return "Wrong variant name"; if (!g.cadence.match(/^[0-9dhms +]+$/)) return "Wrong characters in time control"; if (!g.fen.match(/^[a-zA-Z0-9, /-]*$/)) @@ -277,28 +275,21 @@ const GameModel = const day = 86400000; db.serialize(function() { let query = - "SELECT id,score,created " + + "SELECT id,created " + "FROM Games "; db.all(query, (err,games) => { games.forEach(g => { query = - "SELECT max(played) AS lastMaj " + + "SELECT count(*) as nbMoves, max(played) AS lastMaj " + "FROM Moves " + "WHERE gid = " + g.id; - db.get(query, (err2,updated) => { - if (!updated.lastMaj) + db.get(query, (err2,mstats) => { + // Remove games still not really started, + // with no action in the last 3 months: + if ((mstats.nbMoves == 0 && tsNow - g.created > 91*day) || + (mstats.nbMoves == 1 && tsNow - mstats.lastMaj > 91*day)) { - 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); - } + return GameModel.remove(g.id); } }); });