From 043699cfb354d65c1cac0f534007d0a9bd55af5e Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 13 May 2016 15:20:55 -0400 Subject: [PATCH] Always use log entry kind cache Fixes #1445 --- data/model/log.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/data/model/log.py b/data/model/log.py index 13c21429d..b5039f407 100644 --- a/data/model/log.py +++ b/data/model/log.py @@ -42,6 +42,11 @@ def get_log_entry_kinds(): return kind_map +def _get_log_entry_kind(name): + kinds = get_log_entry_kinds() + return kinds[name] + + def get_aggregated_logs(start_time, end_time, performer=None, repository=None, namespace=None, ignore=None): date = db.extract_date('day', LogEntry.datetime) @@ -83,7 +88,7 @@ def log_action(kind_name, user_or_organization_name, performer=None, repository= if account is None: account = User.select(fn.Min(User.id)).tuples().get()[0] - kind = LogEntryKind.get(LogEntryKind.name == kind_name) + kind = _get_log_entry_kind(kind_name) metadata_json = json.dumps(metadata, default=_json_serialize) LogEntry.create(kind=kind, account=account, performer=performer, repository=repository, ip=ip, metadata_json=metadata_json, @@ -121,22 +126,22 @@ def _get_repository_events(repository, time_delta, time_delta_earlier, clause): def get_repository_pushes(repository, time_delta, time_delta_earlier): - push_repo = LogEntryKind.get(name='push_repo') + push_repo = _get_log_entry_kind('push_repo') clauses = (LogEntry.kind == push_repo) return _get_repository_events(repository, time_delta, time_delta_earlier, clauses) def get_repository_pulls(repository, time_delta, time_delta_earlier): - repo_pull = LogEntryKind.get(name='pull_repo') - repo_verb = LogEntryKind.get(name='repo_verb') + repo_pull = _get_log_entry_kind('pull_repo') + repo_verb = _get_log_entry_kind('repo_verb') clauses = ((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb)) return _get_repository_events(repository, time_delta, time_delta_earlier, clauses) def get_repository_usage(): one_month_ago = date.today() - timedelta(weeks=4) - repo_pull = LogEntryKind.get(name='pull_repo') - repo_verb = LogEntryKind.get(name='repo_verb') + repo_pull = _get_log_entry_kind('pull_repo') + repo_verb = _get_log_entry_kind('repo_verb') return (LogEntry .select(LogEntry.ip, LogEntry.repository) .where((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb))