Skip to content

Commit

Permalink
Don't load retro data if not needed. Merge retro data faster if it's …
Browse files Browse the repository at this point in the history
…present. (#5141)
  • Loading branch information
sulkaharo authored Oct 22, 2019
1 parent 2d07c54 commit fab2453
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var PADDING_BOTTOM = 30
, FOCUS_MIN = 30
;

var loadTime = Date.now();

function init (client, d3, $) {
var chart = { };

Expand Down Expand Up @@ -192,7 +194,9 @@ function init (client, d3, $) {
chart.brush = d3.brushX()
.on('start', brushStarted)
.on('brush', function brush (time) {
client.loadRetroIfNeeded();
// layouting the graph causes a brushed event
// ignore retro data load the first two seconds
if (Date.now() - loadTime > 2000) client.loadRetroIfNeeded();
client.brushed(time);
})
.on('end', brushEnded);
Expand Down
14 changes: 13 additions & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,22 @@ client.load = function load (serverSettings, callback) {
client.ddata.inRetroMode = inRetroMode();
client.ddata.profile = profile;

// retro data only ever contains device statuses
// Cleate a clone of the data for the sandbox given to plugins

var mergedStatuses = client.ddata.devicestatus;

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

var clonedData = _.clone(client.ddata);
clonedData.devicestatus = mergedStatuses;

client.sbx = sandbox.clientInit(
client.ctx
, new Date(time).getTime() //make sure we send a timestamp
, _.merge({}, client.retro.data || {}, client.ddata)
, clonedData
);

//all enabled plugins get a chance to set properties, even if they aren't shown
Expand Down

0 comments on commit fab2453

Please sign in to comment.