From b98758daf840a8e8df6c6cdfa4b55d07d220eee5 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 13 Jan 2015 08:44:49 -0800 Subject: [PATCH] [Persistence] Fix bug in id filtering Fix bug when filtering out namespaced identifiers when reading domain object models from persistence; filter operation was breaking the logic of pairing ids back to loaded models by index. Corrects behavior introduced to reduce latency when loading the telemetry hierarchy, part of WARP Server integration, WTD-644. --- .../core/src/models/PersistedModelProvider.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/platform/core/src/models/PersistedModelProvider.js b/platform/core/src/models/PersistedModelProvider.js index eb23eac809..8dee85b0e4 100644 --- a/platform/core/src/models/PersistedModelProvider.js +++ b/platform/core/src/models/PersistedModelProvider.js @@ -20,22 +20,30 @@ define( * models should be retrieved. */ function PersistedModelProvider(persistenceService, $q, SPACE) { + // Load a single object model from persistence + function loadModel(id) { + return persistenceService.readObject(SPACE, id); + } + + // Promise all persisted models (in id->model form) function promiseModels(ids) { - return $q.all(ids.filter(function (id) { - // Filter out "namespaced" identifiers; these are - // not expected to be found in database. See WTD-659. - return id.indexOf(":") === -1; - }).map(function (id) { - // Read remaining objects from persistence - return persistenceService.readObject(SPACE, id); - })).then(function (models) { - // Packaged the result as id->object + // Package the result as id->model + function packageResult(models) { var result = {}; ids.forEach(function (id, index) { result[id] = models[index]; }); return result; + } + + // Filter out "namespaced" identifiers; these are + // not expected to be found in database. See WTD-659. + ids = ids.filter(function (id) { + return id.indexOf(":") === -1; }); + + // Give a promise for all persistence lookups... + return $q.all(ids.map(loadModel)).then(packageResult); } return {