parent
59e8905aed
commit
e1f955a3f6
5 changed files with 147 additions and 0 deletions
|
@ -124,3 +124,38 @@ def get_repository_usage():
|
|||
.where(LogEntry.datetime >= one_month_ago)
|
||||
.group_by(LogEntry.ip, LogEntry.repository)
|
||||
.count())
|
||||
|
||||
|
||||
def get_stale_logs_start_id():
|
||||
""" Gets the oldest log entry. """
|
||||
try:
|
||||
return (LogEntry
|
||||
.select(LogEntry.id)
|
||||
.order_by(LogEntry.id)
|
||||
.limit(1)
|
||||
.tuples())[0][0]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
|
||||
def get_stale_logs_end_id(cutoff_date):
|
||||
""" Gets the most recent ID created before the cutoff_date. """
|
||||
try:
|
||||
return (LogEntry
|
||||
.select(LogEntry.id)
|
||||
.where(LogEntry.datetime <= cutoff_date)
|
||||
.order_by(LogEntry.id.desc())
|
||||
.limit(1)
|
||||
.tuples())[0][0]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
|
||||
def get_stale_logs(start_id, end_id):
|
||||
""" Returns all the logs with IDs between start_id and end_id inclusively. """
|
||||
return LogEntry.select().where((LogEntry.id >= start_id), (LogEntry.id <= end_id))
|
||||
|
||||
|
||||
def delete_stale_logs(start_id, end_id):
|
||||
""" Deletes all the logs with IDs between start_id and end_id. """
|
||||
LogEntry.delete().where((LogEntry.id >= start_id), (LogEntry.id <= end_id)).execute()
|
||||
|
|
Reference in a new issue