mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 08:25:31 +00:00
[Core] Aggregate models more intelligently
When aggregating models from multiple providers, prefer the more recent version, based on its modified timestamp. WTD-1033.
This commit is contained in:
parent
f9b8b17ff6
commit
a640af6bf9
@ -18,6 +18,19 @@ define(
|
||||
*/
|
||||
function ModelAggregator($q, providers) {
|
||||
|
||||
// Pick a domain object model to use, favoring the one
|
||||
// with the most recent timestamp
|
||||
function pick(a, b) {
|
||||
if (!a) {
|
||||
return b;
|
||||
}
|
||||
if (!b) {
|
||||
return b;
|
||||
}
|
||||
return (a.modified || Number.NEGATIVE_INFINITY) >
|
||||
(b.modified || Number.NEGATIVE_INFINITY) ? a : b;
|
||||
}
|
||||
|
||||
// Merge results from multiple providers into one
|
||||
// large result object.
|
||||
function mergeModels(provided, ids) {
|
||||
@ -25,7 +38,7 @@ define(
|
||||
ids.forEach(function (id) {
|
||||
provided.forEach(function (models) {
|
||||
if (models[id]) {
|
||||
result[id] = models[id];
|
||||
result[id] = pick(result[id], models[id]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user