PR changes in response to comments
This commit is contained in:
parent
c767aafcd6
commit
8ed8367404
1 changed files with 14 additions and 6 deletions
|
@ -2778,11 +2778,19 @@ def cancel_repository_build(build, work_queue):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _get_repository_events(repository, time_delta, time_delta_earlier, clause):
|
def _get_repository_events(repository, time_delta, time_delta_earlier, clause):
|
||||||
|
""" Returns a pair representing the count of the number of events for the given
|
||||||
|
repository in each of the specified time deltas. The date ranges are calculated by
|
||||||
|
taking the current time today and subtracting the time delta given. Since
|
||||||
|
we want to grab *two* ranges, we restrict the second range to be greater
|
||||||
|
than the first (i.e. referring to an earlier time), so we can conduct the
|
||||||
|
lookup in a single query. The clause is used to further filter the kind of
|
||||||
|
events being found.
|
||||||
|
"""
|
||||||
since = date.today() - time_delta
|
since = date.today() - time_delta
|
||||||
since_earlier = date.today() - time_delta_earlier
|
since_earlier = date.today() - time_delta_earlier
|
||||||
|
|
||||||
if since_earlier >= since:
|
if since_earlier >= since:
|
||||||
raise Exception('time_delta_earlier must be greater than time_delta')
|
raise ValueError('time_delta_earlier must be greater than time_delta')
|
||||||
|
|
||||||
# This uses a CASE WHEN inner clause to further filter the count.
|
# This uses a CASE WHEN inner clause to further filter the count.
|
||||||
formatted = since.strftime('%Y-%m-%d')
|
formatted = since.strftime('%Y-%m-%d')
|
||||||
|
@ -2799,22 +2807,22 @@ def _get_repository_events(repository, time_delta, time_delta_earlier, clause):
|
||||||
|
|
||||||
|
|
||||||
def get_repository_pushes(repository, time_delta, time_delta_earlier):
|
def get_repository_pushes(repository, time_delta, time_delta_earlier):
|
||||||
push_repo = LogEntryKind.get(name = 'push_repo')
|
push_repo = LogEntryKind.get(name='push_repo')
|
||||||
clauses = (LogEntry.kind == push_repo)
|
clauses = (LogEntry.kind == push_repo)
|
||||||
return _get_repository_events(repository, time_delta, time_delta_earlier, clauses)
|
return _get_repository_events(repository, time_delta, time_delta_earlier, clauses)
|
||||||
|
|
||||||
|
|
||||||
def get_repository_pulls(repository, time_delta, time_delta_earlier):
|
def get_repository_pulls(repository, time_delta, time_delta_earlier):
|
||||||
repo_pull = LogEntryKind.get(name = 'pull_repo')
|
repo_pull = LogEntryKind.get(name='pull_repo')
|
||||||
repo_verb = LogEntryKind.get(name = 'repo_verb')
|
repo_verb = LogEntryKind.get(name='repo_verb')
|
||||||
clauses = ((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb))
|
clauses = ((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb))
|
||||||
return _get_repository_events(repository, time_delta, time_delta_earlier, clauses)
|
return _get_repository_events(repository, time_delta, time_delta_earlier, clauses)
|
||||||
|
|
||||||
|
|
||||||
def get_repository_usage():
|
def get_repository_usage():
|
||||||
one_month_ago = date.today() - timedelta(weeks=4)
|
one_month_ago = date.today() - timedelta(weeks=4)
|
||||||
repo_pull = LogEntryKind.get(name = 'pull_repo')
|
repo_pull = LogEntryKind.get(name='pull_repo')
|
||||||
repo_verb = LogEntryKind.get(name = 'repo_verb')
|
repo_verb = LogEntryKind.get(name='repo_verb')
|
||||||
return (LogEntry.select(LogEntry.ip, LogEntry.repository)
|
return (LogEntry.select(LogEntry.ip, LogEntry.repository)
|
||||||
.where((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb))
|
.where((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb))
|
||||||
.where(~(LogEntry.repository >> None))
|
.where(~(LogEntry.repository >> None))
|
||||||
|
|
Reference in a new issue