From 8c2e965f6ea5caada496254f4c5193b23a160d8a Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Mon, 7 Sep 2020 18:23:04 +0530 Subject: [PATCH] Fixed excessive CPU usage by stopping the indefinite growth of the graph dataset. Fixes #5794 --- docs/en_US/release_notes_4_26.rst | 3 ++- web/pgadmin/dashboard/static/js/Graphs.jsx | 23 ++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/docs/en_US/release_notes_4_26.rst b/docs/en_US/release_notes_4_26.rst index a14c59f61..3337a6745 100644 --- a/docs/en_US/release_notes_4_26.rst +++ b/docs/en_US/release_notes_4_26.rst @@ -35,4 +35,5 @@ Bug fixes | `Issue #5765 `_ - Fixed an issue in the query tool when columns are having the same name as javascript object internal functions. | `Issue #5766 `_ - Fixed string indices must be integers issue for PostgreSQL < 9.3. | `Issue #5773 `_ - Fixed an issue where the application ignores the fixed port configuration value. -| `Issue #5775 `_ - Ensure that 'setup-web.sh' should work in Debian 10. \ No newline at end of file +| `Issue #5775 `_ - Ensure that 'setup-web.sh' should work in Debian 10. +| `Issue #5794 `_ - Fixed excessive CPU usage by stopping the indefinite growth of the graph dataset. \ No newline at end of file diff --git a/web/pgadmin/dashboard/static/js/Graphs.jsx b/web/pgadmin/dashboard/static/js/Graphs.jsx index ac1c1605f..e8862a109 100644 --- a/web/pgadmin/dashboard/static/js/Graphs.jsx +++ b/web/pgadmin/dashboard/static/js/Graphs.jsx @@ -67,7 +67,6 @@ export function getStatsUrl(sid=-1, did=-1, chart_names=[]) { * data to get the new state. */ export function statsReducer(state, action) { - let newState = {}; if(action.reset) { return action.reset; @@ -82,21 +81,14 @@ export function statsReducer(state, action) { } Object.keys(action.incoming).forEach(label => { - if(state[label]) { - if(state[label].length >= X_AXIS_LENGTH) { - state[label].unshift(); - } - newState[label] = [ - action.counter ? action.incoming[label] - action.counterData[label] : action.incoming[label], - ...state[label], - ]; - } else { - newState[label] = [ - action.counter ? action.incoming[label] - action.counterData[label] : action.incoming[label], - ]; + let newEle = action.counter ? action.incoming[label] - action.counterData[label] : action.incoming[label]; + state[label] = state[label] || []; + if(state[label].length >= X_AXIS_LENGTH) { + state[label].pop(); } + state[label].unshift(newEle); }); - return newState; + return state; } const chartsDefault = { @@ -263,6 +255,7 @@ export function GraphsWrapper(props) { const toStatsLegendRef = useRef(); const bioStatsLegendRef = useRef(); const options = useMemo(()=>({ + normalized: true, legendCallback: legendCallback, animation: { duration: 0, @@ -385,4 +378,4 @@ GraphsWrapper.propTypes = { showTooltip: PropTypes.bool.isRequired, showDataPoints: PropTypes.bool.isRequired, isDatabase: PropTypes.bool.isRequired, -}; \ No newline at end of file +};