X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=851197226658029e5ea234a748d73a7c41d55329;hb=6f2f94374f1e73c375edf732d9425e575e81fff7;hp=080cab3c69b38ec3f2c5b84f780cd02c03133672;hpb=f14572c4a22425033735253eabbaa2d8dbb53d05;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 080cab3c..85119722 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -232,11 +232,18 @@ const GameModel = "JOIN Variants v " + " ON g.vid = v.id " + "WHERE " + - " score <> '*' AND " + - " created < " + cursor + " AND " + + " score <> '*' AND" + + " created < " + cursor + " AND" + " (" + - " (" + uid + " = white AND NOT deletedByWhite) OR " + - " (" + uid + " = black AND NOT deletedByBlack)" + + " (" + + " white = " + uid + " AND" + + " (deletedByWhite IS NULL OR NOT deletedByWhite)" + + " )" + + " OR " + + " (" + + " black = " + uid + " AND" + + " (deletedByBlack IS NULL OR NOT deletedByBlack)" + + " )" + " ) "; query += "ORDER BY created DESC " + @@ -293,10 +300,7 @@ const GameModel = // Check all that is possible (required) in obj: return ( ( - !obj.move || ( - !!(obj.move.played.toString().match(/^[0-9]+$/)) && - !!(obj.move.idx.toString().match(/^[0-9]+$/)) - ) + !obj.move || !!(obj.move.idx.toString().match(/^[0-9]+$/)) ) && ( !obj.drawOffer || !!(obj.drawOffer.match(/^[wbtn]$/)) ) && ( @@ -450,7 +454,7 @@ const GameModel = "SELECT gid, count(*) AS nbMoves, MAX(played) AS lastMaj " + "FROM Moves " + "GROUP BY gid"; - db.get(query, (err2, mstats) => { + db.all(query, (err2, mstats) => { // Reorganize moves data to avoid too many array lookups: let movesGroups = {}; mstats.forEach(ms => { @@ -460,18 +464,18 @@ const GameModel = }; }); // Remove games still not really started, - // with no action in the last 3 months: + // with no action in the last 2 weeks: let toRemove = []; games.forEach(g => { if ( ( !movesGroups[g.id] && - tsNow - g.created > 91*day + tsNow - g.created > 14*day ) || ( movesGroups[g.id].nbMoves == 1 && - tsNow - movesGroups[g.id].lastMaj > 91*day + tsNow - movesGroups[g.id].lastMaj > 14*day ) ) { toRemove.push(g.id);