Merge pull request #3328 from quay/optimize-tags-query
Optimize the list active tags query
This commit is contained in:
commit
19b9d6c927
2 changed files with 20 additions and 12 deletions
|
@ -204,18 +204,24 @@ def get_tag_manifest_digests(tags):
|
||||||
return {manifest.tag_id: manifest.digest for manifest in manifests}
|
return {manifest.tag_id: manifest.digest for manifest in manifests}
|
||||||
|
|
||||||
|
|
||||||
def list_active_repo_tags(repo, start_id=None, limit=None):
|
def list_active_repo_tags(repo, start_id=None, limit=None, include_images=True):
|
||||||
""" Returns all of the active, non-hidden tags in a repository, joined to they images
|
""" Returns all of the active, non-hidden tags in a repository, joined to they images
|
||||||
and (if present), their manifest.
|
and (if present), their manifest.
|
||||||
"""
|
"""
|
||||||
query = _tag_alive(RepositoryTag
|
if include_images:
|
||||||
.select(RepositoryTag, Image, ImageStorage, TagManifest.digest)
|
query = _tag_alive(RepositoryTag
|
||||||
.join(Image)
|
.select(RepositoryTag, Image, ImageStorage, TagManifest.digest)
|
||||||
.join(ImageStorage)
|
.join(Image)
|
||||||
.where(RepositoryTag.repository == repo, RepositoryTag.hidden == False)
|
.join(ImageStorage)
|
||||||
.switch(RepositoryTag)
|
.where(RepositoryTag.repository == repo, RepositoryTag.hidden == False)
|
||||||
.join(TagManifest, JOIN.LEFT_OUTER)
|
.switch(RepositoryTag)
|
||||||
.order_by(RepositoryTag.id))
|
.join(TagManifest, JOIN.LEFT_OUTER)
|
||||||
|
.order_by(RepositoryTag.id))
|
||||||
|
else:
|
||||||
|
query = _tag_alive(RepositoryTag
|
||||||
|
.select(RepositoryTag)
|
||||||
|
.where(RepositoryTag.repository == repo, RepositoryTag.hidden == False)
|
||||||
|
.order_by(RepositoryTag.id))
|
||||||
|
|
||||||
if start_id is not None:
|
if start_id is not None:
|
||||||
query = query.where(RepositoryTag.id >= start_id)
|
query = query.where(RepositoryTag.id >= start_id)
|
||||||
|
|
|
@ -271,9 +271,11 @@ class PreOCIModel(SharedModel, RegistryDataInterface):
|
||||||
operation on repositories with a lot of tags, and should be avoided for more targetted
|
operation on repositories with a lot of tags, and should be avoided for more targetted
|
||||||
operations wherever possible.
|
operations wherever possible.
|
||||||
"""
|
"""
|
||||||
# NOTE: include_legacy_images isn't used here because `list_active_repo_tags` includes the
|
if not include_legacy_images:
|
||||||
# information already, so we might as well just use it. However, the new model classes will
|
tags = model.tag.list_active_repo_tags(repository_ref._db_id, start_pagination_id, limit,
|
||||||
# *not* include it by default, so we make it a parameter now.
|
include_images=False)
|
||||||
|
return [Tag.for_repository_tag(tag) for tag in tags]
|
||||||
|
|
||||||
tags = model.tag.list_active_repo_tags(repository_ref._db_id, start_pagination_id, limit)
|
tags = model.tag.list_active_repo_tags(repository_ref._db_id, start_pagination_id, limit)
|
||||||
return [Tag.for_repository_tag(tag,
|
return [Tag.for_repository_tag(tag,
|
||||||
legacy_image=LegacyImage.for_image(tag.image),
|
legacy_image=LegacyImage.for_image(tag.image),
|
||||||
|
|
Reference in a new issue