Remove inner query for ancestors lookup on get_matching_tags
This commit is contained in:
parent
8b2e4d3bcf
commit
e583be3914
2 changed files with 16 additions and 16 deletions
|
@ -17,23 +17,18 @@ from util.canonicaljson import canonicalize
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_repository_image_and_deriving(docker_image_id, storage_uuid):
|
||||
""" Returns all matching images with the given docker image ID and storage uuid, along with any
|
||||
images which have the image ID as parents.
|
||||
def get_image_with_storage(docker_image_id, storage_uuid):
|
||||
""" Returns the image with the given docker image ID and storage uuid or None if none.
|
||||
"""
|
||||
try:
|
||||
image_found = (Image
|
||||
.select()
|
||||
.join(ImageStorage)
|
||||
.where(Image.docker_image_id == docker_image_id,
|
||||
ImageStorage.uuid == storage_uuid)
|
||||
.get())
|
||||
return (Image
|
||||
.select()
|
||||
.join(ImageStorage)
|
||||
.where(Image.docker_image_id == docker_image_id,
|
||||
ImageStorage.uuid == storage_uuid)
|
||||
.get())
|
||||
except Image.DoesNotExist:
|
||||
return Image.select().where(Image.id < 0) # Empty query
|
||||
|
||||
ancestors_pattern = '%s%s/%%' % (image_found.ancestors, image_found.id)
|
||||
return Image.select().where((Image.ancestors ** ancestors_pattern) |
|
||||
(Image.id == image_found.id))
|
||||
return None
|
||||
|
||||
|
||||
def get_parent_images_with_placements(namespace_name, repository_name, image_obj):
|
||||
|
|
|
@ -56,14 +56,19 @@ def _tag_alive(query, now_ts=None):
|
|||
def get_matching_tags(docker_image_id, storage_uuid, *args):
|
||||
""" Returns a query pointing to all tags that contain the image with the
|
||||
given docker_image_id and storage_uuid. """
|
||||
image_query = image.get_repository_image_and_deriving(docker_image_id, storage_uuid)
|
||||
image_row = image.get_image_with_storage(docker_image_id, storage_uuid)
|
||||
if image_row is None:
|
||||
return RepositoryTag.select().where(RepositoryTag.id < 0) # Empty query.
|
||||
|
||||
ancestors_str = '%s%s/%%' % (image_row.ancestors, image_row.id)
|
||||
return _tag_alive(RepositoryTag
|
||||
.select(*args)
|
||||
.distinct()
|
||||
.join(Image)
|
||||
.join(ImageStorage)
|
||||
.where(Image.id << image_query, RepositoryTag.hidden == False))
|
||||
.where(RepositoryTag.hidden == False)
|
||||
.where((Image.id == image_row.id) |
|
||||
(Image.ancestors ** ancestors_str)))
|
||||
|
||||
|
||||
def get_tags_for_image(image_id, *args):
|
||||
|
|
Reference in a new issue