Skip to content

Commit

Permalink
fix devicestatus retro merge (#5193)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcunningh authored and sulkaharo committed Nov 10, 2019
1 parent 9c42fed commit c4ee62b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ client.load = function load (serverSettings, callback) {
adjustCurrentSGVClasses(value, isCurrent);
}

function mergeDeviceStatus (retro, ddata) {
var result = retro.map(x => Object.assign(x, ddata.find(y => y._id == x._id)));

var missingInRetro = ddata.filter(y => !retro.find(x => x._id == y._id));

result.push(...missingInRetro);

return result;
}

function updatePlugins (time) {

//TODO: doing a clone was slow, but ok to let plugins muck with data?
Expand All @@ -482,7 +492,7 @@ client.load = function load (serverSettings, callback) {
var mergedStatuses = client.ddata.devicestatus;

if (client.retro.data) {
mergedStatuses = _.merge({}, client.retro.data.devicestatus, client.ddata.devicestatus);
mergedStatuses = mergeDeviceStatus(client.retro.data.devicestatus, client.ddata.devicestatus);
}

var clonedData = _.clone(client.ddata);
Expand Down

0 comments on commit c4ee62b

Please sign in to comment.