[Search] Infinite cycle check

in indexItems in the generic provider.
This commit is contained in:
slhale 2015-08-06 10:23:03 -07:00
parent 44dce05ec5
commit 1a4d7618c1

View File

@ -48,6 +48,7 @@ define(
*/
function GenericSearchProvider($q, objectService, workerService, ROOTS) {
var worker = workerService.run('genericSearchWorker'),
indexed = {},
pendingQueries = {};
// pendingQueries is a dictionary with the key value pairs st
// the key is the timestamp and the value is the promise
@ -122,21 +123,25 @@ define(
// Helper function for getItems(). Indexes the tree.
function indexItems(nodes) {
console.log('nodes', nodes);
nodes.forEach(function (node) {
// Index each item with the web worker
indexItem(node);
var id = node.getId();
if (node.hasCapability('composition')) {
// This node has children
node.getCapability('composition').invoke().then(function (children) {
// Index the children
if (children.constructor === Array) {
indexItems(children);
} else {
indexItems([children]);
}
});
if (!indexed[id]) {
// Index each item with the web worker
indexItem(node);
indexed[id] = true;
if (node.hasCapability('composition')) {
// This node has children
node.getCapability('composition').invoke().then(function (children) {
// Index the children
if (children.constructor === Array) {
indexItems(children);
} else {
indexItems([children]);
}
});
}
}
});
}