+
+ cleanGamesDb: function()
+ {
+ const tsNow = Date.now();
+ // 86400000 = 24 hours in milliseconds
+ const day = 86400000;
+ db.serialize(function() {
+ let query =
+ "SELECT id,score " +
+ "FROM Games ";
+ db.all(query, (err,games) => {
+ games.forEach(g => {
+ query =
+ "SELECT max(played) AS lastMaj " +
+ "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)
+ {
+ GameModel.remove(g.id);
+ }
+ });
+ });
+ });
+ });
+ },