[Search] Infinite cycle check

in indexItems in the generic provider.
This commit is contained in:
slhale 2015-08-06 10:24:05 -07:00
parent f76f6548a5
commit a2eabc1b08

View File

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