From: Ant Zucaro Date: Sun, 18 Dec 2016 23:25:37 +0000 (-0500) Subject: Use pagination on the maps page instead of a full select count(*). X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9c717036ae008b2592158f5376f5693347ed0c68;p=xonotic%2Fxonstat.git Use pagination on the maps page instead of a full select count(*). --- diff --git a/xonstat/templates/map_index.mako b/xonstat/templates/map_index.mako index 481b9a8..0dc1211 100644 --- a/xonstat/templates/map_index.mako +++ b/xonstat/templates/map_index.mako @@ -1,6 +1,5 @@ <%inherit file="base.mako"/> <%namespace name="nav" file="nav.mako" /> -<%namespace file="navlinks.mako" import="navlinks" /> <%block name="navigation"> ${nav.nav('maps')} @@ -10,8 +9,11 @@ Map Index -% if not maps: -

Sorry, no maps yet. Get playing!

+% if not maps and last is not None: +

Sorry, no more maps!

+ +% elif not maps: +

Sorry, no maps yet. Get playing!

% else:
@@ -53,8 +55,18 @@ % endfor - - ${navlinks("map_index", maps.page, maps.last_page)} + % if len(maps) == 20: +
+
+ +
+
+ % endif +
% endif diff --git a/xonstat/views/map.py b/xonstat/views/map.py index f1daf4a..ccc1529 100644 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -24,15 +24,21 @@ class MapIndex(object): """Common parameter parsing.""" self.request = request self.page = request.params.get("page", 1) + self.last = request.params.get("last", None) - # all views share this data, so we'll precalculate + # all views share this data, so we'll pre-calculate self.maps = self.map_index() def map_index(self): """Returns the raw data shared by all renderers.""" try: - map_q = DBSession.query(Map).order_by(Map.map_id.desc()) - maps = Page(map_q, self.page, items_per_page=INDEX_COUNT, url=page_url) + map_q = DBSession.query(Map) + + if self.last: + map_q = map_q.filter(Map.map_id < self.last) + + map_q = map_q.order_by(Map.map_id.desc()).limit(INDEX_COUNT) + maps = map_q.all() except Exception as e: log.debug(e) @@ -42,14 +48,21 @@ class MapIndex(object): def html(self): """For rendering this data using something HTML-based.""" + # build the query string + query = {} + if len(self.maps) > 1: + query['last'] = self.maps[-1].map_id + return { 'maps': self.maps, + 'query': query, } def json(self): """For rendering this data using JSON.""" return { 'maps': [m.to_dict() for m in self.maps], + 'last': self.last, }