From: Ant Zucaro Date: Mon, 19 Nov 2012 02:29:54 +0000 (-0500) Subject: Use the new helpers on the map info page. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e744237b4b5dfd5cd00bb8418bf62404cb920b46;p=xonotic%2Fxonstat.git Use the new helpers on the map info page. Big performance boost! Was 1.5s (on my machine) and now <1s. --- diff --git a/xonstat/templates/map_info.mako b/xonstat/templates/map_info.mako index 5fbd2af..cda2035 100644 --- a/xonstat/templates/map_info.mako +++ b/xonstat/templates/map_info.mako @@ -154,36 +154,28 @@ ${parent.title()} Type + Server Time Winner - % for (game, srv, map, pgstat) in recent_games: - % if game != '-': + % for rg in recent_games: - View - ${game.game_type_cd} - ${game.fuzzy_date()} + View + ${rg.game_type_cd} + ${rg.server_name} + ${rg.fuzzy_date} - % if pgstat.player_id > 2: - ${pgstat.nick_html_colors()|n} - + % if rg.player_id > 2: + ${rg.nick_html_colors|n} % else: - ${pgstat.nick_html_colors()|n} - + ${rg.nick_html_colors|n} % endif + - % else: - - - - - - - - - - - % endif - % endfor - + % endfor + diff --git a/xonstat/views/map.py b/xonstat/views/map.py index 5fbc772..ee149a1 100644 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -3,11 +3,11 @@ import sqlalchemy.sql.functions as func import sqlalchemy.sql.expression as expr from collections import namedtuple from datetime import datetime, timedelta -from pyramid.response import Response from sqlalchemy import desc from webhelpers.paginate import Page, PageURL from xonstat.models import * from xonstat.util import page_url, html_colors +from xonstat.views.helpers import RecentGame, recent_games_q log = logging.getLogger(__name__) @@ -66,14 +66,9 @@ def _map_info_data(request): try: gmap = DBSession.query(Map).filter_by(map_id=map_id).one() - # recent games on this map - recent_games = DBSession.query(Game, Server, Map, PlayerGameStat).\ - filter(Game.server_id==Server.server_id).\ - filter(Game.map_id==Map.map_id).\ - filter(Game.map_id==map_id).\ - filter(PlayerGameStat.game_id==Game.game_id).\ - filter(PlayerGameStat.rank==1).\ - order_by(expr.desc(Game.start_dt)).all()[0:recent_games_count] + # recent games played in descending order + rgs = recent_games_q(map_id=map_id).limit(recent_games_count).all() + recent_games = [RecentGame(row) for row in rgs] # top players by score top_scorers = DBSession.query(Player.player_id, Player.nick,