From cab675c8ca0a3492367bce4ded7ffcea729d4b5d Mon Sep 17 00:00:00 2001 From: slhale Date: Wed, 12 Aug 2015 10:57:37 -0700 Subject: [PATCH] [Search] Timeout length & indexed check Changed timeout to 0 ms. Changed check for already indexed to an empty return. --- platform/search/src/GenericSearchProvider.js | 57 ++++++++++---------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/platform/search/src/GenericSearchProvider.js b/platform/search/src/GenericSearchProvider.js index 762a47bff3..dae2cab9a9 100644 --- a/platform/search/src/GenericSearchProvider.js +++ b/platform/search/src/GenericSearchProvider.js @@ -39,13 +39,13 @@ define( * * @constructor * @param $q Angular's $q, for promise consolidation. - * @param $timeout Angular's $timeout, for delayed funtion execution. + * @param $timeout Angular's $timeout, for delayed function execution. * @param {ObjectService} objectService The service from which * domain objects can be gotten. * @param {WorkerService} workerService The service which allows * more easy creation of web workers. - * @param {GENERIC_SEARCH_ROOTS[]} ROOTS An array of the root - * domain objects. + * @param {GENERIC_SEARCH_ROOTS} ROOTS An array of the root + * domain objects' IDs. */ function GenericSearchProvider($q, $timeout, objectService, workerService, ROOTS) { var worker = workerService.run('genericSearchWorker'), @@ -127,30 +127,32 @@ define( nodes.forEach(function (node) { var id = node && node.getId && node.getId(); - // If we have not yet indexed this item, index it - if (!indexed[id]) { - // Index each item with the web worker - indexItem(node); - indexed[id] = true; - - if (node.hasCapability && node.hasCapability('composition')) { - // This node has children - - // Make sure that this is async, so doesn't block up page - $timeout(function () { - // Get the children... - node.useCapability('composition').then(function (children) { - $timeout(function () { - // ... then index the children - if (children.constructor === Array) { - indexItems(children); - } else { - indexItems([children]); - } - }, 100); - }); - }, 100); - } + // If we have already indexed this item, stop here + if (indexed[id]) { + return; + } + + // Index each item with the web worker + indexItem(node); + indexed[id] = true; + + + // If this node has children, index those + if (node && node.hasCapability && node.hasCapability('composition')) { + // Make sure that this is async, so doesn't block up page + $timeout(function () { + // Get the children... + node.useCapability('composition').then(function (children) { + $timeout(function () { + // ... then index the children + if (children.constructor === Array) { + indexItems(children); + } else { + indexItems([children]); + } + }, 0); + }); + }, 0); } // Watch for changes to this item, in case it gets new children @@ -192,7 +194,6 @@ define( }); } - // For documentation, see query below function query(input, timestamp, maxResults, timeout) { var terms = [],