Faster cache lookup by removing a join with the ImagePlacementTable, removing the extra loop to add the locations and filtering the images looked up by the base image
This commit is contained in:
parent
fd65ca5916
commit
e70343d849
3 changed files with 39 additions and 1 deletions
|
@ -104,7 +104,9 @@ class BuildJob(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Build an in-memory tree of the full heirarchy of images in the repository.
|
# Build an in-memory tree of the full heirarchy of images in the repository.
|
||||||
all_images = model.get_repository_images(repo_namespace, repo_name)
|
all_images = model.get_repository_images_directly(repo_build.repository,
|
||||||
|
with_ancestor=base_image)
|
||||||
|
|
||||||
all_tags = model.list_repository_tags(repo_namespace, repo_name)
|
all_tags = model.list_repository_tags(repo_namespace, repo_name)
|
||||||
tree = ImageTree(all_images, all_tags, base_filter=base_image.id)
|
tree = ImageTree(all_images, all_tags, base_filter=base_image.id)
|
||||||
|
|
||||||
|
|
|
@ -1751,6 +1751,21 @@ def get_matching_repository_images(namespace_name, repository_name, docker_image
|
||||||
|
|
||||||
return _get_repository_images_base(namespace_name, repository_name, modify_query)
|
return _get_repository_images_base(namespace_name, repository_name, modify_query)
|
||||||
|
|
||||||
|
|
||||||
|
def get_repository_images_directly(repository, with_ancestor=None):
|
||||||
|
query = (Image
|
||||||
|
.select(Image, ImageStorage)
|
||||||
|
.join(ImageStorage)
|
||||||
|
.where(Image.repository == repository))
|
||||||
|
|
||||||
|
if with_ancestor:
|
||||||
|
ancestors_string = '%s%s/' % (with_ancestor.ancestors, with_ancestor.id)
|
||||||
|
query = query.where((Image.ancestors ** (ancestors_string + '%')) |
|
||||||
|
(Image.id == with_ancestor.id))
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
|
|
||||||
def get_repository_images(namespace_name, repository_name):
|
def get_repository_images(namespace_name, repository_name):
|
||||||
return _get_repository_images_base(namespace_name, repository_name, lambda q: q)
|
return _get_repository_images_base(namespace_name, repository_name, lambda q: q)
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,27 @@ class TestImageTree(unittest.TestCase):
|
||||||
self.assertEquals('staging', tree.tag_containing_image(result[0]))
|
self.assertEquals('staging', tree.tag_containing_image(result[0]))
|
||||||
|
|
||||||
|
|
||||||
|
def test_longest_path_simple_repo_direct_lookup(self):
|
||||||
|
repository = model.get_repository(NAMESPACE, SIMPLE_REPO)
|
||||||
|
all_images = list(model.get_repository_images(NAMESPACE, SIMPLE_REPO))
|
||||||
|
all_tags = list(model.list_repository_tags(NAMESPACE, SIMPLE_REPO))
|
||||||
|
|
||||||
|
base_image = self._get_base_image(all_images)
|
||||||
|
tag_image = all_tags[0].image
|
||||||
|
|
||||||
|
def checker(index, image):
|
||||||
|
return True
|
||||||
|
|
||||||
|
filtered_images = model.get_repository_images_directly(repository, with_ancestor=base_image)
|
||||||
|
self.assertEquals(set([f.id for f in filtered_images]), set([a.id for a in all_images]))
|
||||||
|
|
||||||
|
tree = ImageTree(filtered_images, all_tags)
|
||||||
|
|
||||||
|
ancestors = tag_image.ancestors.split('/')[2:-1] # Skip the first image.
|
||||||
|
result = tree.find_longest_path(base_image.id, checker)
|
||||||
|
self.assertEquals(3, len(result))
|
||||||
|
self.assertEquals('latest', tree.tag_containing_image(result[-1]))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Reference in a new issue