Instead of sending DB IDs, send "internal IDs" which are DB IDs hashed. This way, we can still calculate the ancestors without hitting the DB further, but without leaking the size of the images table
This commit is contained in:
parent
dd4037e324
commit
63628678b8
7 changed files with 59 additions and 36 deletions
|
@ -5757,7 +5757,7 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
}
|
||||
|
||||
var currentTag = $scope.repository.tags[$scope.tag];
|
||||
if (image.dbid == currentTag.dbid) {
|
||||
if (image.internal_id == currentTag.internal_id) {
|
||||
classes += 'tag-image ';
|
||||
}
|
||||
|
||||
|
@ -5767,15 +5767,15 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
var forAllTagImages = function(tag, callback, opt_cutoff) {
|
||||
if (!tag) { return; }
|
||||
|
||||
if (!$scope.imageByDBID) {
|
||||
$scope.imageByDBID = [];
|
||||
if (!$scope.imageByInternalId) {
|
||||
$scope.imageByInternalId = [];
|
||||
for (var i = 0; i < $scope.images.length; ++i) {
|
||||
var currentImage = $scope.images[i];
|
||||
$scope.imageByDBID[currentImage.dbid] = currentImage;
|
||||
$scope.imageByInternalId[currentImage.internal_id] = currentImage;
|
||||
}
|
||||
}
|
||||
|
||||
var tag_image = $scope.imageByDBID[tag.dbid];
|
||||
var tag_image = $scope.imageByInternalId[tag.internal_id];
|
||||
if (!tag_image) {
|
||||
return;
|
||||
}
|
||||
|
@ -5784,7 +5784,7 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
|
||||
var ancestors = tag_image.ancestors.split('/').reverse();
|
||||
for (var i = 0; i < ancestors.length; ++i) {
|
||||
var image = $scope.imageByDBID[ancestors[i]];
|
||||
var image = $scope.imageByInternalId[ancestors[i]];
|
||||
if (image) {
|
||||
if (image == opt_cutoff) {
|
||||
return;
|
||||
|
@ -5810,7 +5810,7 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
var getIdsForTag = function(currentTag) {
|
||||
var ids = {};
|
||||
forAllTagImages(currentTag, function(image) {
|
||||
ids[image.dbid] = true;
|
||||
ids[image.internal_id] = true;
|
||||
}, $scope.imageCutoff);
|
||||
return ids;
|
||||
};
|
||||
|
@ -5820,8 +5820,8 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
for (var currentTagName in $scope.repository.tags) {
|
||||
var currentTag = $scope.repository.tags[currentTagName];
|
||||
if (currentTag != tag) {
|
||||
for (var dbid in getIdsForTag(currentTag)) {
|
||||
delete toDelete[dbid];
|
||||
for (var internal_id in getIdsForTag(currentTag)) {
|
||||
delete toDelete[internal_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5830,7 +5830,7 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
var images = [];
|
||||
for (var i = 0; i < $scope.images.length; ++i) {
|
||||
var image = $scope.images[i];
|
||||
if (toDelete[image.dbid]) {
|
||||
if (toDelete[image.internal_id]) {
|
||||
images.push(image);
|
||||
}
|
||||
}
|
||||
|
@ -5841,7 +5841,7 @@ quayApp.directive('tagSpecificImagesView', function () {
|
|||
return result;
|
||||
}
|
||||
|
||||
return b.dbid - a.dbid;
|
||||
return b.sort_index - a.sort_index;
|
||||
});
|
||||
|
||||
$scope.tagSpecificImages = images;
|
||||
|
|
|
@ -493,7 +493,7 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
|
|||
};
|
||||
|
||||
$scope.findImageForTag = function(tag) {
|
||||
return tag && $scope.imageByDBID && $scope.imageByDBID[tag.dbid];
|
||||
return tag && $scope.imageByInternalId && $scope.imageByInternalId[tag.internal_id];
|
||||
};
|
||||
|
||||
$scope.createOrMoveTag = function(image, tagName, opt_invalid) {
|
||||
|
@ -681,9 +681,9 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
|
|||
};
|
||||
|
||||
var forAllTagImages = function(tag, callback) {
|
||||
if (!tag || !$scope.imageByDBID) { return; }
|
||||
if (!tag || !$scope.imageByInternalId) { return; }
|
||||
|
||||
var tag_image = $scope.imageByDBID[tag.dbid];
|
||||
var tag_image = $scope.imageByInternalId[tag.internal_id];
|
||||
if (!tag_image) { return; }
|
||||
|
||||
// Callback the tag's image itself.
|
||||
|
@ -693,7 +693,7 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
|
|||
if (!tag_image.ancestors) { return; }
|
||||
var ancestors = tag_image.ancestors.split('/');
|
||||
for (var i = 0; i < ancestors.length; ++i) {
|
||||
var image = $scope.imageByDBID[ancestors[i]];
|
||||
var image = $scope.imageByInternalId[ancestors[i]];
|
||||
if (image) {
|
||||
callback(image);
|
||||
}
|
||||
|
@ -782,10 +782,10 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
|
|||
$scope.specificImages = [];
|
||||
|
||||
// Build various images for quick lookup of images.
|
||||
$scope.imageByDBID = {};
|
||||
$scope.imageByInternalId = {};
|
||||
for (var i = 0; i < $scope.images.length; ++i) {
|
||||
var currentImage = $scope.images[i];
|
||||
$scope.imageByDBID[currentImage.dbid] = currentImage;
|
||||
$scope.imageByInternalId[currentImage.internal_id] = currentImage;
|
||||
}
|
||||
|
||||
// Dispose of any existing tree.
|
||||
|
|
|
@ -307,8 +307,8 @@ ImageHistoryTree.prototype.setHighlightedPath_ = function(image) {
|
|||
this.markPath_(this.currentNode_, false);
|
||||
}
|
||||
|
||||
var imageByDBID = this.imageByDBID_;
|
||||
var currentNode = imageByDBID[image.dbid];
|
||||
var imageByInternalId = this.imageByInternalId_;
|
||||
var currentNode = imageByInternalId[image.internal_id];
|
||||
if (currentNode) {
|
||||
this.markPath_(currentNode, true);
|
||||
this.currentNode_ = currentNode;
|
||||
|
@ -386,7 +386,7 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
var formatted = {"name": "No images found"};
|
||||
|
||||
// Build a node for each image.
|
||||
var imageByDBID = {};
|
||||
var imageByInternalId = {};
|
||||
for (var i = 0; i < this.images_.length; ++i) {
|
||||
var image = this.images_[i];
|
||||
var imageNode = {
|
||||
|
@ -395,9 +395,9 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
"image": image,
|
||||
"tags": image.tags
|
||||
};
|
||||
imageByDBID[image.dbid] = imageNode;
|
||||
imageByInternalId[image.internal_id] = imageNode;
|
||||
}
|
||||
this.imageByDBID_ = imageByDBID;
|
||||
this.imageByInternalId_ = imageByInternalId;
|
||||
|
||||
// For each node, attach it to its immediate parent. If there is no immediate parent,
|
||||
// then the node is the root.
|
||||
|
@ -408,10 +408,10 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
// Skip images that are currently uploading.
|
||||
if (image.uploading) { continue; }
|
||||
|
||||
var imageNode = imageByDBID[image.dbid];
|
||||
var imageNode = imageByInternalId[image.internal_id];
|
||||
var ancestors = this.getAncestors_(image);
|
||||
var immediateParent = ancestors[ancestors.length - 1] * 1;
|
||||
var parent = imageByDBID[immediateParent];
|
||||
var immediateParent = ancestors[ancestors.length - 1];
|
||||
var parent = imageByInternalId[immediateParent];
|
||||
if (parent) {
|
||||
// Add a reference to the parent. This makes walking the tree later easier.
|
||||
imageNode.parent = parent;
|
||||
|
@ -442,7 +442,7 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
// Skip images that are currently uploading.
|
||||
if (image.uploading) { continue; }
|
||||
|
||||
var imageNode = imageByDBID[image.dbid];
|
||||
var imageNode = imageByInternalId[image.internal_id];
|
||||
maxChildCount = Math.max(maxChildCount, this.determineMaximumChildCount_(imageNode));
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ ImageHistoryTree.prototype.setTag_ = function(tagName) {
|
|||
return;
|
||||
}
|
||||
|
||||
var imageByDBID = this.imageByDBID_;
|
||||
var imageByInternalId = this.imageByInternalId_;
|
||||
|
||||
// Save the current tag.
|
||||
var previousTagName = this.currentTag_;
|
||||
|
@ -596,10 +596,10 @@ ImageHistoryTree.prototype.setTag_ = function(tagName) {
|
|||
// Skip images that are currently uploading.
|
||||
if (image.uploading) { continue; }
|
||||
|
||||
var imageNode = this.imageByDBID_[image.dbid];
|
||||
var imageNode = this.imageByInternalId_[image.internal_id];
|
||||
var ancestors = this.getAncestors_(image);
|
||||
var immediateParent = ancestors[ancestors.length - 1] * 1;
|
||||
var parent = imageByDBID[immediateParent];
|
||||
var immediateParent = ancestors[ancestors.length - 1];
|
||||
var parent = imageByInternalId[immediateParent];
|
||||
if (parent && imageNode.highlighted) {
|
||||
var arr = parent.children;
|
||||
if (parent._children) {
|
||||
|
|
Reference in a new issue