From 0d5147701fea4653c2bf1ca697fc27886d18ca83 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Wed, 24 Dec 2014 22:32:17 -0500 Subject: [PATCH] Use the GIN index wherever possible. --- xonstat/views/helpers.py | 4 +++- xonstat/views/player.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xonstat/views/helpers.py b/xonstat/views/helpers.py index 8a10a48..d8b3211 100644 --- a/xonstat/views/helpers.py +++ b/xonstat/views/helpers.py @@ -116,11 +116,13 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, if player_id is not None: if force_player_id: recent_games_q = recent_games_q.\ - filter(PlayerGameStat.player_id==player_id) + filter(PlayerGameStat.player_id==player_id).\ + filter(Game.players.contains([player_id])) else: recent_games_q = recent_games_q.\ filter(PlayerGameStat.scoreboardpos==1).\ filter(Game.game_id==pgstat_alias.game_id).\ + filter(Game.players.contains([player_id])).\ filter(pgstat_alias.player_id==player_id) else: recent_games_q = recent_games_q.\ diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 479ea1e..c3e5120 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -89,7 +89,8 @@ def get_games_played(player_id): "FROM games g, " "player_game_stats pgs " "WHERE g.game_id = pgs.game_id " - "AND pgs.player_id = :player_id) win_loss " + "AND pgs.player_id = :player_id " + "AND g.players @> ARRAY[:player_id]) win_loss " "GROUP BY game_type_cd " ).params(player_id=player_id).all() @@ -167,6 +168,7 @@ def get_overall_stats(player_id): "player_game_stats pgs " "WHERE g.game_id = pgs.game_id " "AND g.game_type_cd = gt.game_type_cd " + "AND g.players @> ARRAY[:player_id] " "AND pgs.player_id = :player_id " "GROUP BY g.game_type_cd, game_type_descr " "UNION " @@ -289,6 +291,7 @@ def get_fav_maps(player_id, game_type_cd=None): "maps m " "WHERE g.game_id = pgs.game_id " "AND g.map_id = m.map_id " + "AND g.players @> ARRAY[:player_id]" "AND pgs.player_id = :player_id " "GROUP BY g.game_type_cd, " "m.map_id, " -- 2.39.2