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.

previous change 292:7b640cb27fe2

viewer.py

Permissions: -rwxr-xr-x

Other formats: Feeds:
#!/usr/bin/env python
from __future__ import absolute_import
import logging
from tornado.ioloop import IOLoop
from tornado.options import define, options
from tornado.web import Application
from candolint import handlers as h, uimodules
from candolint.models import database
from candolint.utils import rel
class CandolintViewer(Application):
def __init__(self, debug=False):
project_re = r'/([.a-z0-9_-]+)/([^/]+)/([^/]+)'
handlers = [
(r'/', h.IndexHandler),
(project_re, h.ProjectHandler),
(project_re + r'/atom', h.AtomHandler),
(project_re + r'/(\d+|latest)(?:/(raw))?', h.CheckHandler),
(project_re + r'/(\d+|latest)/dot\.svg', h.DotHandler),
(project_re + r'/(\d+|latest)/compare/(\d+|latest)', h.CompareHandler),
(project_re + r'/status\.svg', h.StatusHandler),
(r'.*', h.ErrorHandler, {'status_code': 404})
]
settings = dict(
static_path=rel('static'),
template_path=rel('templates'),
ui_modules=uimodules,
debug=debug
)
super(CandolintViewer, self).__init__(handlers, **settings)
if debug:
logging.getLogger('peewee').setLevel(logging.DEBUG)
database.init(rel('database.sqlite'))
def listen(self, port, address='', **kwargs):
name = self.__class__.__name__
logging.info('%s is serving on http://%s:%d/', name, address, port)
super(CandolintViewer, self).listen(port, address, **kwargs)
def main():
define('listen', metavar='IP', default='127.0.0.1')
define('port', metavar='PORT', default=8033, type=int)
define('xheaders', metavar='True|False', default=False, type=bool)
define('debug', metavar='True|False', default=False, type=bool)
options.parse_command_line()
application = CandolintViewer(options.debug)
application.listen(options.port, options.listen, xheaders=options.xheaders)
IOLoop.current().start()
if __name__ == '__main__':
main()