[Search] Break up item indexing

Use timeouts to make the generic search's item
indexing not block up the page.
This commit is contained in:
slhale
2015-08-12 09:42:21 -07:00
parent 48693df51f
commit 3b62f1a979
2 changed files with 18 additions and 10 deletions

View File

@ -14,7 +14,7 @@
"provides": "searchService",
"type": "provider",
"implementation": "GenericSearchProvider.js",
"depends": [ "$q", "objectService", "workerService", "GENERIC_SEARCH_ROOTS" ]
"depends": [ "$q", "$timeout", "objectService", "workerService", "GENERIC_SEARCH_ROOTS" ]
},
{
"provides": "searchService",

View File

@ -39,6 +39,7 @@ define(
*
* @constructor
* @param $q Angular's $q, for promise consolidation.
* @param $timeout Angular's $timeout, for delayed funtion execution.
* @param {ObjectService} objectService The service from which
* domain objects can be gotten.
* @param {WorkerService} workerService The service which allows
@ -46,7 +47,7 @@ define(
* @param {GENERIC_SEARCH_ROOTS[]} ROOTS An array of the root
* domain objects.
*/
function GenericSearchProvider($q, objectService, workerService, ROOTS) {
function GenericSearchProvider($q, $timeout, objectService, workerService, ROOTS) {
var worker = workerService.run('genericSearchWorker'),
indexed = {},
pendingQueries = {};
@ -134,14 +135,21 @@ define(
if (node.hasCapability && 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]);
}
});
// 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);
}
}