diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-12-27 13:39:18 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-01-01 16:47:38 +0100 |
commit | acd3d804bde233e216f35e9202ab9d26d894472f (patch) | |
tree | e6930bd96e551331b04a4a3ee8025d471b6e57dd | |
parent | cb2a5796df9733145e97b13a8fde6f842fc3476d (diff) | |
download | server-acd3d804bde233e216f35e9202ab9d26d894472f.tar.gz |
Purge games automatically.
Remove unstarted open games, abandoned active games,
and finished solo games.
-rw-r--r-- | server.js | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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 */ |