diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-11-15 00:16:32 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-11-15 00:17:10 +0100 |
commit | 6ba80db16551bbafa11385d7f98393731357ab93 (patch) | |
tree | 50a779d8d41fe8bc6648161abbf73e22eff5ecf0 | |
parent | b9d5983b17adbd238fdb8a41d926dacf53730675 (diff) | |
download | server-6ba80db16551bbafa11385d7f98393731357ab93.tar.gz |
Improve /games query.
-rw-r--r-- | server.js | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -922,8 +922,8 @@ const SQL_INSERT_REMATCH = SQL(` const QUERY_LIST_GAMES = SQL(` SELECT * FROM game_view - WHERE private=0 AND status < 2 - ORDER BY status ASC, mtime DESC + WHERE private=0 AND status=? + ORDER BY mtime DESC `); const QUERY_LIST_GAMES_OF_TITLE = SQL(` @@ -980,16 +980,15 @@ function annotate_games(games, user_id) { app.get('/games', may_be_logged_in, function (req, res) { LOG(req, "GET /join"); - let games; + let open_games = QUERY_LIST_GAMES.all(0); + let active_games = QUERY_LIST_GAMES.all(1); if (req.isAuthenticated()) { - games = QUERY_LIST_GAMES.all(); - annotate_games(games, req.user.user_id); + annotate_games(open_games, req.user.user_id); + annotate_games(active_games, req.user.user_id); } else { - games = QUERY_LIST_GAMES.all({user_id: 0}); - annotate_games(games, 0); + annotate_games(open_games, 0); + annotate_games(active_games, 0); } - let open_games = games.filter(game => game.status === 0); - let active_games = games.filter(game => game.status === 1); res.set("Cache-Control", "no-store"); res.render('games.ejs', { user: req.user, |