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.
incoming.py
Permissions: -rwxr-xr-x
from __future__ import absolute_import from argparse import ArgumentParser, FileType from urlparse import urlparse from tornado.escape import json_encode from candolint.models import database, Project, Change, Check from candolint.utils import parse_timestamp, rel def parse_project_url(url): parts = [part for part in parsed.path.split('/') if part] name = '/'.join(parts[1:]) return domain, user, name def match_linter_output(line): m = re.match(r'^(?P<filename>.+):(?P<line_number>\d+):\d+: ', line) item['filename'] = m.group('filename') item['line_number'] = int(m.group('line_number')) item['link_start'] = m.start('filename') item['link_end'] = m.end('line_number') # https://pep8.readthedocs.io/en/latest/intro.html#error-codes (r'^[EWFCN]\d{3}', 'warning'), (r'^\[error\]', 'error'), (r'^\[warning\]', 'warning'), (r'^\(E\d{3}\)', 'error'), (r'^\(W\d{3}\)', 'warning'), (r'.* \(E\d{3}\)$', 'error'), (r'.* \(W\d{3}\)$', 'warning'), for regex, cls in patterns: m = re.match(regex, rest) return errors, warnings, item line = line.rstrip('\r\n') if line.startswith(meta_prefix): rest = line[len(meta_prefix):] m = re.match('^task: (\w+)$', rest) m = re.match('^job failed', rest) m = re.match('^job (started|finished): ([\dT:+-]+)$', rest) if m.group(1) == 'started': started = parse_timestamp(m.group(2)) elif m.group(1) == 'finished': finished = parse_timestamp(m.group(2)) m = re.match('^project URL: (\S+)$', rest) m = re.match('^commit: (?:(\d+):)?(\w+)$', rest) m = re.match('^commit branch: (.+)$', rest) m = re.match('^commit ref names:.* HEAD -> (\S+)(, |$)', rest) m = re.match('^commit date: (.+)$', rest) m = re.match('^commit author: (.+)$', rest) m = re.match('^commit message: (.+)$', rest) de, dw, extra = match_linter_output(line) if not url or not node or not branch: domain, user, name = parse_project_url(url) with database.transaction(): project, created = Project.manual_upsert( change, created = Change.manual_upsert( ordinal=Check.get_next_ordinal(project), lines=json_encode(result), parser = ArgumentParser() 'file', type=FileType('r'), nargs='?', default=sys.stdin, help='file to read from (if - or not specified, read from stdin)') '-d', '--debug', action='store_true', help='enable debugging output') args = parser.parse_args() database.init(rel('database.sqlite')) database.create_tables([Project, Change, Check], safe=True) logger = logging.getLogger('peewee') logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) if __name__ == '__main__':