From a45054bf2ed84c0eb63a074956fb96d80b44f2d9 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 17 Jul 2014 15:16:22 -0400 Subject: [PATCH] Change tag_view to avoid a DB lookup and only return the tag's image ID. We map the ID in the frontend based on the image data returned --- endpoints/api/repository.py | 22 +---------- static/js/controllers.js | 69 +++++++++++++++++++--------------- static/partials/view-repo.html | 15 ++++++-- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/endpoints/api/repository.py b/endpoints/api/repository.py index 215caa1b5..17a35fea1 100644 --- a/endpoints/api/repository.py +++ b/endpoints/api/repository.py @@ -138,21 +138,6 @@ class RepositoryList(ApiResource): return response -def image_view(image): - extended_props = image - if image.storage and image.storage.id: - extended_props = image.storage - - command = extended_props.command - return { - 'id': image.docker_image_id, - 'created': format_date(extended_props.created), - 'comment': extended_props.comment, - 'command': json.loads(command) if command else None, - 'ancestors': image.ancestors, - 'dbid': image.id, - 'size': extended_props.image_size - } @resource('/v1/repository/') class Repository(RepositoryParamResource): @@ -181,13 +166,10 @@ class Repository(RepositoryParamResource): logger.debug('Get repo: %s/%s' % (namespace, repository)) def tag_view(tag): - image = model.get_tag_image(namespace, repository, tag.name) - if not image: - return {} - return { 'name': tag.name, - 'image': image_view(image), + 'image_id': tag.image.docker_image_id, + 'dbid': tag.image.id } organization = None diff --git a/static/js/controllers.js b/static/js/controllers.js index 0b19eba2e..985a6c361 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -466,31 +466,6 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi addedDisplayed - removedDisplayed - changedDisplayed; }; - $scope.setImage = function(imageId, opt_updateURL) { - var image = null; - for (var i = 0; i < $scope.images.length; ++i) { - var currentImage = $scope.images[i]; - if (currentImage.id == imageId || currentImage.id.substr(0, 12) == imageId) { - image = currentImage; - break; - } - } - - if (!image) { return; } - - $scope.currentTag = null; - $scope.currentImage = image; - $scope.loadImageChanges(image); - if ($scope.tree) { - $scope.tree.setImage(image.id); - } - - if (opt_updateURL) { - $location.search('tag', null); - $location.search('image', imageId.substr(0, 12)); - } - }; - $scope.showAddTag = function(image) { $scope.toTagImage = image; $('#addTagModal').modal('show'); @@ -513,6 +488,10 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi $('#confirmdeleteTagModal').modal('show'); }; + $scope.findImageForTag = function(tag) { + return tag && $scope.imageByDBID && $scope.imageByDBID[tag.dbid]; + }; + $scope.createOrMoveTag = function(image, tagName, opt_invalid) { if (opt_invalid) { return; } @@ -592,13 +571,38 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi return size; }; + $scope.setImage = function(imageId, opt_updateURL) { + var image = null; + for (var i = 0; i < $scope.images.length; ++i) { + var currentImage = $scope.images[i]; + if (currentImage.id == imageId || currentImage.id.substr(0, 12) == imageId) { + image = currentImage; + break; + } + } + + if (!image) { return; } + + $scope.currentTag = null; + $scope.currentImage = image; + $scope.loadImageChanges(image); + if ($scope.tree) { + $scope.tree.setImage(image.id); + } + + if (opt_updateURL) { + $location.search('tag', null); + $location.search('image', imageId.substr(0, 12)); + } + }; + $scope.setTag = function(tagName, opt_updateURL) { var repo = $scope.repo; if (!repo) { return; } var proposedTag = repo.tags[tagName]; if (!proposedTag) { - // We must find a good default + // We must find a good default. for (tagName in repo.tags) { if (!proposedTag || tagName == 'latest') { proposedTag = repo.tags[tagName]; @@ -608,8 +612,8 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi if (proposedTag) { $scope.currentTag = proposedTag; - $scope.currentImage = proposedTag.image; - $scope.loadImageChanges($scope.currentImage); + $scope.currentImage = null; + if ($scope.tree) { $scope.tree.setTag(proposedTag.name); } @@ -686,9 +690,14 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi var forAllTagImages = function(tag, callback) { if (!tag || !$scope.imageByDBID) { return; } - callback(tag.image); + var tag_image = $scope.imageByDBID[tag.dbid]; + if (!tag_image) { return; } - var ancestors = tag.image.ancestors.split('/'); + // Callback the tag's image itself. + callback(tag_image); + + // Callback any parent images. + var ancestors = tag_image.ancestors.split('/'); for (var i = 0; i < ancestors.length; ++i) { var image = $scope.imageByDBID[ancestors[i]]; if (image) { diff --git a/static/partials/view-repo.html b/static/partials/view-repo.html index 915bc52ec..7d683cd2b 100644 --- a/static/partials/view-repo.html +++ b/static/partials/view-repo.html @@ -77,7 +77,7 @@ content-changed="updateForDescription" field-title="'repository description'"> -
+
This repository is empty
@@ -100,14 +100,14 @@
-
+
A build is currently processing. If this takes longer than an hour, please contact us
-
+
@@ -163,7 +163,14 @@
Last Modified
-
+
+ +
+ +
+
+
Total Compressed Size