Switch get repo API to use a single list tags query
Should make things faster since the join occurs on the database side
This commit is contained in:
parent
d86b0254b3
commit
ab2f044331
4 changed files with 48 additions and 15 deletions
|
@ -83,13 +83,30 @@ def filter_tags_have_repository_event(query, event):
|
|||
.order_by(RepositoryTag.lifetime_start_ts.desc()))
|
||||
|
||||
|
||||
def get_tag_manifests(tags):
|
||||
""" Returns a map from tag ID to its associated manifest, if any. """
|
||||
def get_tag_manifest_digests(tags):
|
||||
""" Returns a map from tag ID to its associated manifest digest, if any. """
|
||||
if not tags:
|
||||
return dict()
|
||||
|
||||
manifests = TagManifest.select().where(TagManifest.tag << [t.id for t in tags])
|
||||
return {manifest.tag_id:manifest for manifest in manifests}
|
||||
manifests = (TagManifest
|
||||
.select(TagManifest.tag, TagManifest.digest)
|
||||
.where(TagManifest.tag << [t.id for t in tags]))
|
||||
|
||||
return {manifest.tag_id: manifest.digest for manifest in manifests}
|
||||
|
||||
|
||||
def list_active_repo_tags(repo):
|
||||
""" 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, TagManifest.digest)
|
||||
.join(Image)
|
||||
.where(RepositoryTag.repository == repo)
|
||||
.switch(RepositoryTag)
|
||||
.join(TagManifest, JOIN_LEFT_OUTER))
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def list_repository_tags(namespace_name, repository_name, include_hidden=False,
|
||||
|
@ -320,7 +337,7 @@ def list_repository_tag_history(repo_obj, page=1, size=100, specific_tag=None):
|
|||
if not tags:
|
||||
return [], {}, False
|
||||
|
||||
manifest_map = get_tag_manifests(tags)
|
||||
manifest_map = get_tag_manifest_digests(tags)
|
||||
return tags[0:size], manifest_map, len(tags) > size
|
||||
|
||||
|
||||
|
|
Reference in a new issue