Performance improvements for the repo API and the new repo UI

This commit is contained in:
Joseph Schorr 2015-03-18 14:47:53 -04:00
parent bc6baae050
commit ab2331a486
9 changed files with 119 additions and 100 deletions

View file

@ -17,7 +17,7 @@ def image_view(image, image_map):
command = extended_props.command
def docker_id(aid):
if not aid:
if not aid or not aid in image_map:
return ''
return image_map[aid]
@ -51,19 +51,26 @@ class RepositoryImageList(RepositoryParamResource):
all_tags = model.list_repository_tags(namespace, repository)
tags_by_image_id = defaultdict(list)
found_image_ids = set()
for tag in all_tags:
tags_by_image_id[tag.image.docker_image_id].append(tag.name)
found_image_ids.add(str(tag.image.id))
found_image_ids.update(tag.image.ancestors.split('/')[1:-1])
image_map = {}
filtered_images = []
for image in all_images:
image_map[str(image.id)] = image.docker_image_id
if str(image.id) in found_image_ids:
image_map[str(image.id)] = image.docker_image_id
filtered_images.append(image)
def add_tags(image_json):
image_json['tags'] = tags_by_image_id[image_json['id']]
return image_json
return {
'images': [add_tags(image_view(image, image_map)) for image in all_images]
'images': [add_tags(image_view(image, image_map)) for image in filtered_images]
}

View file

@ -188,16 +188,9 @@ class Repository(RepositoryParamResource):
return tag_info
organization = None
try:
organization = model.get_organization(namespace)
except model.InvalidOrganizationException:
pass
is_public = model.repository_is_public(namespace, repository)
repo = model.get_repository(namespace, repository)
if repo:
tags = model.list_repository_tags(namespace, repository)
tags = model.list_repository_tags(namespace, repository, include_storage=True)
tag_dict = {tag.name: tag_view(tag) for tag in tags}
can_write = ModifyRepositoryPermission(namespace, repository).can()
can_admin = AdministerRepositoryPermission(namespace, repository).can()
@ -206,6 +199,7 @@ class Repository(RepositoryParamResource):
is_starred = (model.repository_is_starred(get_authenticated_user(), repo)
if get_authenticated_user() else False)
is_public = model.is_repository_public(repo)
return {
'namespace': namespace,
@ -216,7 +210,7 @@ class Repository(RepositoryParamResource):
'can_admin': can_admin,
'is_public': is_public,
'is_building': len(list(active_builds)) > 0,
'is_organization': bool(organization),
'is_organization': repo.namespace_user.organization,
'is_starred': is_starred,
'status_token': repo.badge_token if not is_public else '',
'stats': {