[Search] New item indexer

This one (hopefully) doesn't fill up the
call stack when there are lots of items.
This commit is contained in:
slhale 2015-08-06 09:51:09 -07:00
parent ae763d000c
commit 1fe492cc3d

View File

@ -121,23 +121,20 @@ define(
worker.onmessage = handleResponse; worker.onmessage = handleResponse;
// Helper function for getItems(). Indexes the tree. // Helper function for getItems(). Indexes the tree.
function itemsHelper(children, i) { function indexItems(nodes) {
// Index the current node var i;
indexItem(children[i]);
if (i >= children.length) { for (i = 0; i < nodes.length; i += 1) {
// Done! // Index each item with the web worker
return children; indexItem(nodes[i]);
} else if (children[i].hasCapability('composition')) {
// This child has children if (nodes[i].hasCapability('composition')) {
return children[i].getCapability('composition').invoke().then(function (grandchildren) { // This node has children
// Add grandchildren to the end of the list nodes[i].getCapability('composition').invoke().then(function (children) {
// They will also be checked for composition // Index the children
return itemsHelper(children.concat(grandchildren), i + 1); indexItems(children);
}); });
} else { }
// This child is a leaf
return itemsHelper(children, i + 1);
} }
} }
@ -154,7 +151,7 @@ define(
} }
// Index all of the roots' descendents // Index all of the roots' descendents
itemsHelper(objects, 0); indexItems(objects);
}); });
} }