Switch tag deletion to use a single query

This commit is contained in:
Joseph Schorr 2015-06-19 14:55:30 -04:00 committed by Joseph Schorr
parent 79101c1055
commit acd86008c8
2 changed files with 60 additions and 39 deletions

View file

@ -97,22 +97,15 @@ def delete_tag(namespace_name, repository_name, tag_name):
found.save()
def garbage_collect_tags(namespace_name, repository_name):
# We do this without using a join to prevent holding read locks on the repository table
repo = _basequery.get_existing_repository(namespace_name, repository_name)
def garbage_collect_tags(repo):
expired_time = get_epoch_timestamp() - repo.namespace_user.removed_tag_expiration_s
tags_to_delete = list(RepositoryTag
.select(RepositoryTag.id)
.where(RepositoryTag.repository == repo,
~(RepositoryTag.lifetime_end_ts >> None),
(RepositoryTag.lifetime_end_ts <= expired_time))
.order_by(RepositoryTag.id))
if len(tags_to_delete) > 0:
(RepositoryTag
.delete()
.where(RepositoryTag.id << tags_to_delete)
.execute())
(RepositoryTag
.delete()
.where(RepositoryTag.repository == repo,
~(RepositoryTag.lifetime_end_ts >> None),
(RepositoryTag.lifetime_end_ts <= expired_time))
.execute())
def get_tag_image(namespace_name, repository_name, tag_name):