Optimize the logs archiving worker to not issue extremely long queries

Fixes https://jira.coreos.com/browse/QUAY-1371
This commit is contained in:
Joseph Schorr 2019-02-26 14:37:42 -05:00
parent 2bebea23f7
commit 91e9fe8050
3 changed files with 79 additions and 32 deletions

View file

@ -151,25 +151,17 @@ def get_stale_logs_start_id(model):
""" Gets the oldest log entry. """
# TODO(LogMigrate): Remove the branch once we're back on a single table.
try:
return (model.select(model.id).order_by(model.id).limit(1).tuples())[0][0]
return (model.select(fn.Min(model.id)).tuples())[0][0]
except IndexError:
return None
def get_stale_logs_cutoff_id(cutoff_date, model):
""" Gets the most recent ID created before the cutoff_date. """
# TODO(LogMigrate): Remove the branch once we're back on a single table.
try:
return (model.select(fn.Max(model.id)).where(model.datetime <= cutoff_date)
.tuples())[0][0]
except IndexError:
return None
def get_stale_logs(start_id, end_id, model):
def get_stale_logs(start_id, end_id, model, cutoff_date):
""" Returns all the logs with IDs between start_id and end_id inclusively. """
# TODO(LogMigrate): Remove the branch once we're back on a single table.
return model.select().where((model.id >= start_id), (model.id <= end_id))
return model.select().where((model.id >= start_id),
(model.id <= end_id),
model.datetime <= cutoff_date)
def delete_stale_logs(start_id, end_id, model):