From acd3d804bde233e216f35e9202ab9d26d894472f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 27 Dec 2023 13:39:18 +0100 Subject: Purge games automatically. Remove unstarted open games, abandoned active games, and finished solo games. --- server.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/server.js b/server.js index 731fc0d..844513c 100644 --- a/server.js +++ b/server.js @@ -2361,6 +2361,54 @@ function ready_game_ticker() { setInterval(ready_game_ticker, 47 * 1000) +const QUERY_PURGE_OPEN_GAMES = SQL(` + delete from + games + where + status = 0 + and not is_match + and not is_ready + and julianday(ctime) < julianday('now', '-10 days') +`) + +const QUERY_PURGE_ACTIVE_GAMES = SQL(` + delete from + games + where + status = 1 + and not is_match + and not is_ready + and julianday(mtime) < julianday('now', '-10 days') +`) + +// don't keep solo games in archive +const QUERY_PURGE_FINISHED_GAMES = SQL(` + delete from + games + where + status > 1 + and not is_opposed + and julianday(mtime) < julianday('now', '-10 days') +`) + +const QUERY_PURGE_MESSAGES = SQL(` + delete from + messages + where + is_deleted_from_inbox and is_deleted_from_outbox +`) + +function purge_game_ticker() { + QUERY_PURGE_OPEN_GAMES.run() + QUERY_PURGE_ACTIVE_GAMES.run() + QUERY_PURGE_FINISHED_GAMES.run() + QUERY_PURGE_MESSAGES.run() +} + +// Purge abandoned games every 31 minutes. +setInterval(purge_game_ticker, 31 * 60 * 1000) +setTimeout(purge_game_ticker, 89 * 1000) + /* * GAME SERVER */ -- cgit v1.2.3