From d51a820fc873119d3f06a0ddf5678fdff67e528c Mon Sep 17 00:00:00 2001 From: loganhz Date: Fri, 15 Mar 2019 09:09:12 +0800 Subject: [PATCH] Fix graph oom issue https://github.com/rancher/rancher/issues/18929 --- .../addon/components/graph-area/component.js | 14 ++---- .../components/metrics-graph/component.js | 47 ++++++++++++++----- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/lib/shared/addon/components/graph-area/component.js b/lib/shared/addon/components/graph-area/component.js index 4ff2a3593..bf53e5263 100644 --- a/lib/shared/addon/components/graph-area/component.js +++ b/lib/shared/addon/components/graph-area/component.js @@ -154,10 +154,10 @@ export default Component.extend(ThrottledResize, { set(this, 'chart', chart); chart.showLoading(LOADING_PARAMS); - this.draw(false); + this.draw(); }, - draw(update = true) { + draw() { const chart = get(this, 'chart'); if ( !chart ) { @@ -248,16 +248,8 @@ export default Component.extend(ThrottledResize, { option.yAxis.max = minMax; } - let newOptions; - - if ( update ) { - newOptions = { series }; - } else { - newOptions = option; - } - chart.clear(); - chart.setOption(newOptions, true); + chart.setOption(option, true); chart.hideLoading(); }, diff --git a/lib/shared/addon/components/metrics-graph/component.js b/lib/shared/addon/components/metrics-graph/component.js index 97a9d71a5..6ddd5a84d 100644 --- a/lib/shared/addon/components/metrics-graph/component.js +++ b/lib/shared/addon/components/metrics-graph/component.js @@ -8,23 +8,44 @@ export default Component.extend({ layout, - rows: null, - graphs: null, - loading: null, - noGraphs: null, - noDataLabel: 'metricsAction.noData', + rows: null, + graphs: null, + loading: null, + noGraphs: null, + noDataLabel: 'metricsAction.noData', + currentGraphs: null, graphsDidChange: observer('graphs', function() { let out = []; const graphs = (get(this, 'graphs') || []); + const newGrahps = graphs.map((graph) => get(graph, 'graph.title') || '').join(','); + const changed = newGrahps !== get(this, 'currentGraphs'); - graphs.forEach((graph, index) => { - if (index % 3 === 0) { - out.pushObject([graph]); - } else { - get(out, 'lastObject').pushObject(graph); - } - }); - set(this, 'rows', out); + set(this, 'currentGraphs', newGrahps); + + if ( changed ) { + graphs.forEach((graph, index) => { + if (index % 3 === 0) { + out.pushObject([graph]); + } else { + get(out, 'lastObject').pushObject(graph); + } + }); + set(this, 'rows', out); + } else { + let rowIndex = -1; + const currentRows = get(this, 'rows') || []; + + graphs.forEach((graph, index) => { + let colIndex = index % 3; + + if ( colIndex === 0 ) { + rowIndex++; + } + let row = currentRows.objectAt(rowIndex) || []; + + set(row.objectAt(colIndex), 'series', get(graph, 'series') ); + }); + } }), });