]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Use the new helpers for the server_info page as well.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 19 Nov 2012 02:48:31 +0000 (21:48 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 19 Nov 2012 02:48:31 +0000 (21:48 -0500)
Another performance boost on my machine! The page loads in
half the time that it did before. Aw yeah.

xonstat/templates/server_info.mako
xonstat/views/server.py

index 04bf6b455d37065478b019c560e0a286ad698a60..74020354342872c1094cc19c33a6b7fbfd433196 100644 (file)
@@ -133,33 +133,22 @@ Server Information
         </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><a href="${request.route_url('map_info', id=map.map_id)}" title="Go to the map detail page for this map">${map.name}</a></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('map_info', id=rg.map_id)}" title="Go to the map detail page for this map">${rg.map_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>
-          % else:
-            ${pgstat.nick_html_colors()|n}
-          </td>
-          % endif
-        </tr>
+            % 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:
-            <tr>
-              <td>-</td>
-              <td>-</td>
-              <td>-</td>
-              <td>-</td>
-              <td>-</td>
-            </tr>
+            ${rg.nick_html_colors|n}
             % endif
+          </td>
+        </tr>
         % endfor
-        </tbody>
+      </tbody>
     </table>
   </div>
 </div>
index b2d7c6df442b7cbdd7fb5b3c0294b00c38dc9aa3..b3de5d1e2ab607163aeedb93c8fc9e2eb35c77eb 100644 (file)
@@ -3,11 +3,11 @@ import sqlalchemy.sql.functions as func
 import sqlalchemy.sql.expression as expr
 import time
 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__)
 
@@ -103,13 +103,8 @@ def _server_info_data(request):
                 for (player_id, nick, score) in top_players]
 
         # recent games played in descending order
-        recent_games = DBSession.query(Game, Server, Map, PlayerGameStat).\
-            filter(Game.server_id==Server.server_id).\
-            filter(Game.map_id==Map.map_id).\
-            filter(PlayerGameStat.game_id==Game.game_id).\
-            filter(PlayerGameStat.rank==1).\
-            filter(Server.server_id==server.server_id).\
-            order_by(expr.desc(Game.start_dt)).all()[0:recent_games_count]
+        rgs = recent_games_q(server_id=server_id).limit(recent_games_count).all()
+        recent_games = [RecentGame(row) for row in rgs]
 
     except Exception as e:
         server = None