Optimize the list active tags query
Some customers are hitting this endpoint rapidly for repositories with many, many tags. This change drops the unnecessary joins, which should reduce database load somewhat.
This commit is contained in:
parent
defd4b3b20
commit
fe45797490
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}
|
||||
|
||||
|
||||
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
|
||||
and (if present), their manifest.
|
||||
"""
|
||||
query = _tag_alive(RepositoryTag
|
||||
.select(RepositoryTag, Image, ImageStorage, TagManifest.digest)
|
||||
.join(Image)
|
||||
.join(ImageStorage)
|
||||
.where(RepositoryTag.repository == repo, RepositoryTag.hidden == False)
|
||||
.switch(RepositoryTag)
|
||||
.join(TagManifest, JOIN.LEFT_OUTER)
|
||||
.order_by(RepositoryTag.id))
|
||||
if include_images:
|
||||
query = _tag_alive(RepositoryTag
|
||||
.select(RepositoryTag, Image, ImageStorage, TagManifest.digest)
|
||||
.join(Image)
|
||||
.join(ImageStorage)
|
||||
.where(RepositoryTag.repository == repo, RepositoryTag.hidden == False)
|
||||
.switch(RepositoryTag)
|
||||
.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:
|
||||
query = query.where(RepositoryTag.id >= start_id)
|
||||
|
|
Reference in a new issue