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);
}
});
});
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 => {
"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);
+ }
}
});
});