Fix bug where we weren't properly caching enum values and we were always looking up the media type when constructing manifests
This commit is contained in:
parent
ed75daf3d9
commit
bbfb0211dc
5 changed files with 51 additions and 21 deletions
|
@ -6,6 +6,7 @@ from enum import Enum, unique
|
|||
from cachetools import lru_cache
|
||||
|
||||
from data import model
|
||||
from data.database import Manifest as ManifestTable
|
||||
from data.registry_model.datatype import datatype, requiresinput, optionalinput
|
||||
from image.docker import ManifestException
|
||||
from image.docker.schemas import parse_manifest_from_bytes
|
||||
|
@ -197,7 +198,7 @@ class Manifest(datatype('Manifest', ['digest', 'media_type', 'internal_manifest_
|
|||
return Manifest(db_id=manifest.id,
|
||||
digest=manifest.digest,
|
||||
internal_manifest_bytes=Bytes.for_string_or_unicode(manifest.manifest_bytes),
|
||||
media_type=manifest.media_type.name,
|
||||
media_type=ManifestTable.media_type.get_name(manifest.media_type_id),
|
||||
inputs=dict(legacy_image=legacy_image, tag_manifest=False))
|
||||
|
||||
@property
|
||||
|
|
|
@ -256,17 +256,31 @@ def test_repository_tags(repo_namespace, repo_name, registry_model):
|
|||
assert tags_map[tag.name] == found_image.docker_image_id
|
||||
|
||||
|
||||
def test_repository_tag_history(registry_model):
|
||||
repository_ref = registry_model.lookup_repository('devtable', 'history')
|
||||
@pytest.mark.parametrize('namespace, name, expected_tag_count, has_expired', [
|
||||
('devtable', 'simple', 2, False),
|
||||
('devtable', 'history', 2, True),
|
||||
('devtable', 'gargantuan', 8, False),
|
||||
('public', 'publicrepo', 1, False),
|
||||
])
|
||||
def test_repository_tag_history(namespace, name, expected_tag_count, has_expired, registry_model):
|
||||
# Pre-cache media type loads to ensure consistent query count.
|
||||
Manifest.media_type.get_name(1)
|
||||
|
||||
repository_ref = registry_model.lookup_repository(namespace, name)
|
||||
|
||||
with assert_query_count(4 if isinstance(registry_model, SplitModel) else 2):
|
||||
history, has_more = registry_model.list_repository_tag_history(repository_ref)
|
||||
assert not has_more
|
||||
assert len(history) == 2
|
||||
assert len(history) == expected_tag_count
|
||||
|
||||
# Ensure the latest tag is marked expired, since there is an expired one.
|
||||
with assert_query_count(1):
|
||||
assert registry_model.has_expired_tag(repository_ref, 'latest')
|
||||
for tag in history:
|
||||
# Retrieve the manifest to ensure it doesn't issue extra queries.
|
||||
tag.manifest
|
||||
|
||||
if has_expired:
|
||||
# Ensure the latest tag is marked expired, since there is an expired one.
|
||||
with assert_query_count(1):
|
||||
assert registry_model.has_expired_tag(repository_ref, 'latest')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('repo_namespace, repo_name', [
|
||||
|
|
Reference in a new issue