]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Use the new helpers on the map info page.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 19 Nov 2012 02:29:54 +0000 (21:29 -0500)
committerJan Behrens <zykure@web.de>
Sun, 23 Dec 2012 14:18:34 +0000 (15:18 +0100)
Big performance boost! Was 1.5s (on my machine) and now <1s.

xonstat/templates/map_info.mako
xonstat/views/map.py

index 5fbd2afe866a2f634727452028d26714f01ab28e..cda2035ba18e5aa3a88b9955b0a3f4976348e2c8 100644 (file)
@@ -154,36 +154,28 @@ ${parent.title()}
         <tr>
           <th></th>
           <th>Type</th>
+          <th>Server</th>
           <th>Time</th>
           <th>Winner</th>
         </tr>
       </thead>
       <tbody>
-        % for (game, srv, map, pgstat) in recent_games:
-        % if game != '-':
+        % for rg in recent_games:
         <tr>
-          <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">View</a></td>
-          <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
-          <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
+          <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">View</a></td>
+          <td class="gt_icon"><img title="${rg.game_type_cd}" src="/static/images/icons/24x24/${rg.game_type_cd}.png" alt="${rg.game_type_cd}" /></td>
+          <td><a href="${request.route_url('server_info', id=rg.server_id)}" title="Go to the detail page for this server">${rg.server_name}</a></td>
+          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
           <td>
-            % if pgstat.player_id > 2:
-            <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a>
-          </td>
+            % if rg.player_id > 2:
+            <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a>
             % else:
-            ${pgstat.nick_html_colors()|n}
-          </td>
+            ${rg.nick_html_colors|n}
             % endif
+          </td>
         </tr>
-        % else:
-        <tr>
-          <td>-</td>
-          <td>-</td>
-          <td>-</td>
-          <td>-</td>
-        </tr>
-        % endif
-    % endfor
-        </tbody>
+        % endfor
+      </tbody>
     </table>
   </div>
 </div>
index 5fbc7727578780308a3a57beb8ce60ca120591ee..ee149a1ef5d0095b99fdee4495872c624b00b8a4 100644 (file)
@@ -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,