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
|
@ -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