Optimize get_tag_image query
No caller uses the image placements or locations, so no need to load them.
This commit is contained in:
parent
338f93c3c8
commit
53538f9001
4 changed files with 45 additions and 25 deletions
|
@ -162,20 +162,40 @@ def garbage_collect_tags(repo):
|
|||
|
||||
logger.debug('Removed %s tags with %s manifests', num_deleted_tags, num_deleted_manifests)
|
||||
|
||||
def get_tag_image(namespace_name, repository_name, tag_name):
|
||||
def limit_to_tag(query):
|
||||
return _tag_alive(query
|
||||
.switch(Image)
|
||||
.join(RepositoryTag)
|
||||
.where(RepositoryTag.name == tag_name))
|
||||
|
||||
images = image.get_repository_images_base(namespace_name, repository_name, limit_to_tag)
|
||||
def _get_repo_tag_image(tag_name, include_storage, modifier):
|
||||
query = Image.select().join(RepositoryTag)
|
||||
|
||||
if include_storage:
|
||||
query = (Image.select(Image, ImageStorage)
|
||||
.join(ImageStorage)
|
||||
.switch(Image)
|
||||
.join(RepositoryTag))
|
||||
|
||||
images = _tag_alive(modifier(query.where(RepositoryTag.name == tag_name)))
|
||||
if not images:
|
||||
raise DataModelException('Unable to find image for tag.')
|
||||
else:
|
||||
return images[0]
|
||||
|
||||
|
||||
def get_repo_tag_image(repo, tag_name, include_storage=False):
|
||||
def modifier(query):
|
||||
return query.where(RepositoryTag.repository == repo)
|
||||
|
||||
return _get_repo_tag_image(tag_name, include_storage, modifier)
|
||||
|
||||
|
||||
def get_tag_image(namespace_name, repository_name, tag_name, include_storage=False):
|
||||
def modifier(query):
|
||||
return (query.switch(RepositoryTag)
|
||||
.join(Repository)
|
||||
.join(Namespace)
|
||||
.where(Namespace.username == namespace_name, Repository.name == repository_name))
|
||||
|
||||
return _get_repo_tag_image(tag_name, include_storage, modifier)
|
||||
|
||||
|
||||
def list_repository_tag_history(repo_obj, page=1, size=100, specific_tag=None):
|
||||
query = (RepositoryTag
|
||||
.select(RepositoryTag, Image)
|
||||
|
|
Reference in a new issue