Merge pull request #1459 from coreos-inc/logentrykindcache

Always use log entry kind cache
This commit is contained in:
josephschorr 2016-05-13 16:43:13 -04:00
commit 81cc004a56

View file

@ -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))