Download:
child 307:6ce60c358c5c
parent 305:b920a1f9267f
306:edefddec933d
Anton Shestakov <av6@dwimlabs.net>, Sun, 24 Sep 2017 12:25:05 +0800
viewer: use subqueries to get data on index page Before, there were bare columns in the aggregate query, their values were undefined (but it somehow worked), as SQLite docs say. Good news is that now this bigger query uses (project_id, ordinal) index and is really fast.

1 файлов изменено, 11 вставок(+), 2 удалений(-) [+]
candolint/handlers.py file | annotate | diff | comparison | revisions
--- a/candolint/handlers.py Sat Sep 23 13:12:20 2017 +0800
+++ b/candolint/handlers.py Sun Sep 24 12:25:05 2017 +0800
@@ -4,7 +4,7 @@
from difflib import unified_diff
from math import ceil
-from peewee import DoesNotExist
+from peewee import fn, DoesNotExist
from tornado.escape import json_decode
from tornado.web import HTTPError, RequestHandler
from tornado.web import ErrorHandler as BaseErrorHandler
@@ -84,12 +84,21 @@
class IndexHandler(BaseHandler):
def get(self):
+ latest = (Check
+ .select(Check.project_id, fn.MAX(Check.ordinal).alias('maxord'))
+ .group_by(Check.project_id)
+ .alias('latest'))
+ check_ids = (Check
+ .select(Check.id)
+ .from_(Check, latest)
+ .where(Check.project_id == latest.c.project_id)
+ .where(Check.ordinal == latest.c.maxord))
checks = (Check
.select(Project, Change, *Check.get_light_fields())
.join(Project)
.switch(Check)
.join(Change)
- .group_by(Check.project)
+ .where(Check.id.in_(check_ids))
.order_by(Check.finished.desc(), Check.ordinal.desc()))
self.render('index.html', checks=checks)