From 635446dae9a0f6a0a1ffb833c630c51ff8e9c52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 11:54:45 +0200 Subject: [PATCH 01/17] Re-implement reloading data at detail pages Start a timer after each successful loading to reload the data after a grace interval. With this change every load function must return a promise. --- gsa/src/web/entity/container.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/gsa/src/web/entity/container.js b/gsa/src/web/entity/container.js index 77feb8af3b..5516dcf0d5 100644 --- a/gsa/src/web/entity/container.js +++ b/gsa/src/web/entity/container.js @@ -46,10 +46,18 @@ class EntityContainer extends React.Component { } componentDidMount() { + this.isRunning = true; + const {id} = this.props; this.load(id); } + componentWillUnmount() { + this.isRunning = false; + + this.clearTimer(); + } + componentDidUpdate() { const {id} = this.props; if (id !== this.state.id) { @@ -58,8 +66,11 @@ class EntityContainer extends React.Component { } load(id) { - this.props.load(id); + this.clearTimer(); + this.setState({id}); + + this.props.load(id).then(() => this.startTimer()); } reload() { @@ -76,13 +87,17 @@ class EntityContainer extends React.Component { return gmp.autorefresh * 1000; } - startTimer(immediate = false) { - const refresh = immediate ? 0 : this.getRefreshInterval(); + startTimer() { + if (!this.isRunning) { + return; + } + + const interval = this.getRefreshInterval(); - if (refresh >= 0) { - this.timer = window.setTimeout(this.handleTimer, refresh); + if (interval > 0) { + this.timer = global.setTimeout(this.handleTimer, interval); log.debug('Started reload timer with id', this.timer, 'and interval of', - refresh, 'milliseconds'); + interval, 'milliseconds'); } } From eacf43b74473b95cfe4debc79513fbc261a94b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 11:57:54 +0200 Subject: [PATCH 02/17] Update detail pages to return a promise from load functions --- gsa/src/web/pages/agents/detailspage.js | 8 ++++---- gsa/src/web/pages/alerts/detailspage.js | 8 ++++---- gsa/src/web/pages/credentials/detailspage.js | 8 ++++---- gsa/src/web/pages/filters/detailspage.js | 8 ++++---- gsa/src/web/pages/groups/detailspage.js | 8 ++++---- gsa/src/web/pages/hosts/detailspage.js | 8 ++++---- gsa/src/web/pages/notes/detailspage.js | 8 ++++---- gsa/src/web/pages/nvts/detailspage.js | 10 +++++----- gsa/src/web/pages/operatingsystems/detailspage.js | 8 ++++---- gsa/src/web/pages/overrides/detailspage.js | 8 ++++---- gsa/src/web/pages/portlists/detailspage.js | 8 ++++---- gsa/src/web/pages/reportformats/detailspage.js | 8 ++++---- gsa/src/web/pages/roles/detailspage.js | 10 +++++----- gsa/src/web/pages/scanconfigs/detailspage.js | 8 ++++---- gsa/src/web/pages/scanners/detailspage.js | 8 ++++---- gsa/src/web/pages/schedules/detailspage.js | 8 ++++---- gsa/src/web/pages/tags/detailspage.js | 8 ++++---- gsa/src/web/pages/targets/detailspage.js | 8 ++++---- gsa/src/web/pages/tasks/detailspage.js | 12 ++++++------ gsa/src/web/pages/users/detailspage.js | 8 ++++---- 20 files changed, 84 insertions(+), 84 deletions(-) diff --git a/gsa/src/web/pages/agents/detailspage.js b/gsa/src/web/pages/agents/detailspage.js index e2ab0d0d1d..527ce46904 100644 --- a/gsa/src/web/pages/agents/detailspage.js +++ b/gsa/src/web/pages/agents/detailspage.js @@ -266,10 +266,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/alerts/detailspage.js b/gsa/src/web/pages/alerts/detailspage.js index 1df7dfd7ee..893097cd20 100644 --- a/gsa/src/web/pages/alerts/detailspage.js +++ b/gsa/src/web/pages/alerts/detailspage.js @@ -239,10 +239,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/credentials/detailspage.js b/gsa/src/web/pages/credentials/detailspage.js index 4ad430cd0e..2305b4d8e5 100644 --- a/gsa/src/web/pages/credentials/detailspage.js +++ b/gsa/src/web/pages/credentials/detailspage.js @@ -350,10 +350,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/filters/detailspage.js b/gsa/src/web/pages/filters/detailspage.js index f5d703a868..194469e336 100644 --- a/gsa/src/web/pages/filters/detailspage.js +++ b/gsa/src/web/pages/filters/detailspage.js @@ -242,10 +242,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/groups/detailspage.js b/gsa/src/web/pages/groups/detailspage.js index a83e5b1c1f..52b5526fa9 100644 --- a/gsa/src/web/pages/groups/detailspage.js +++ b/gsa/src/web/pages/groups/detailspage.js @@ -240,10 +240,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsSubjectFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsSubjectFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/hosts/detailspage.js b/gsa/src/web/pages/hosts/detailspage.js index b32d184990..2ec8dfbbe2 100644 --- a/gsa/src/web/pages/hosts/detailspage.js +++ b/gsa/src/web/pages/hosts/detailspage.js @@ -412,10 +412,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/notes/detailspage.js b/gsa/src/web/pages/notes/detailspage.js index d0032ba657..ef28112dc9 100644 --- a/gsa/src/web/pages/notes/detailspage.js +++ b/gsa/src/web/pages/notes/detailspage.js @@ -317,10 +317,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/nvts/detailspage.js b/gsa/src/web/pages/nvts/detailspage.js index f489c892ea..aaac128256 100644 --- a/gsa/src/web/pages/nvts/detailspage.js +++ b/gsa/src/web/pages/nvts/detailspage.js @@ -353,11 +353,11 @@ const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadNotesFunc = loadNotes(gmp); const loadOverridesFunc = loadOverrides(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadNotesFunc(nvtIdFilter(id))); - dispatch(loadOverridesFunc(nvtIdFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadNotesFunc(nvtIdFilter(id))), + dispatch(loadOverridesFunc(nvtIdFilter(id))), + ]); }; export default withEntityContainer('task', { diff --git a/gsa/src/web/pages/operatingsystems/detailspage.js b/gsa/src/web/pages/operatingsystems/detailspage.js index 0c49117c56..64b064e974 100644 --- a/gsa/src/web/pages/operatingsystems/detailspage.js +++ b/gsa/src/web/pages/operatingsystems/detailspage.js @@ -318,10 +318,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/overrides/detailspage.js b/gsa/src/web/pages/overrides/detailspage.js index 23b331b1c4..8c467ff375 100644 --- a/gsa/src/web/pages/overrides/detailspage.js +++ b/gsa/src/web/pages/overrides/detailspage.js @@ -317,10 +317,10 @@ Page.propTypes = { const load = gmp => { const loadOverride = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadOverride(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadOverride(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/portlists/detailspage.js b/gsa/src/web/pages/portlists/detailspage.js index 17a757246d..153586b3c1 100644 --- a/gsa/src/web/pages/portlists/detailspage.js +++ b/gsa/src/web/pages/portlists/detailspage.js @@ -298,10 +298,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/reportformats/detailspage.js b/gsa/src/web/pages/reportformats/detailspage.js index 2141b6f1ca..32d3889452 100644 --- a/gsa/src/web/pages/reportformats/detailspage.js +++ b/gsa/src/web/pages/reportformats/detailspage.js @@ -345,10 +345,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/roles/detailspage.js b/gsa/src/web/pages/roles/detailspage.js index 2e6f03f291..105c8b6f33 100644 --- a/gsa/src/web/pages/roles/detailspage.js +++ b/gsa/src/web/pages/roles/detailspage.js @@ -336,11 +336,11 @@ const generalPermissionsFilter = id => const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsSubjectFilter(id))); - dispatch(loadPermissionsFunc(generalPermissionsFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsSubjectFilter(id))), + dispatch(loadPermissionsFunc(generalPermissionsFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/scanconfigs/detailspage.js b/gsa/src/web/pages/scanconfigs/detailspage.js index bacf33a726..c62113f557 100644 --- a/gsa/src/web/pages/scanconfigs/detailspage.js +++ b/gsa/src/web/pages/scanconfigs/detailspage.js @@ -482,10 +482,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/scanners/detailspage.js b/gsa/src/web/pages/scanners/detailspage.js index a8e47af215..59a34e77e9 100644 --- a/gsa/src/web/pages/scanners/detailspage.js +++ b/gsa/src/web/pages/scanners/detailspage.js @@ -290,10 +290,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/schedules/detailspage.js b/gsa/src/web/pages/schedules/detailspage.js index 77925fbdf1..29cf786aee 100644 --- a/gsa/src/web/pages/schedules/detailspage.js +++ b/gsa/src/web/pages/schedules/detailspage.js @@ -240,10 +240,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/tags/detailspage.js b/gsa/src/web/pages/tags/detailspage.js index 052e2ced15..1b6117091c 100644 --- a/gsa/src/web/pages/tags/detailspage.js +++ b/gsa/src/web/pages/tags/detailspage.js @@ -282,10 +282,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/targets/detailspage.js b/gsa/src/web/pages/targets/detailspage.js index ca842d2761..d7c577e57f 100644 --- a/gsa/src/web/pages/targets/detailspage.js +++ b/gsa/src/web/pages/targets/detailspage.js @@ -307,10 +307,10 @@ const TargetPermissions = withComponentDefaults({ const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { diff --git a/gsa/src/web/pages/tasks/detailspage.js b/gsa/src/web/pages/tasks/detailspage.js index d417aab921..81db78d0a9 100644 --- a/gsa/src/web/pages/tasks/detailspage.js +++ b/gsa/src/web/pages/tasks/detailspage.js @@ -559,12 +559,12 @@ const load = gmp => { const loadPermissionsFunc = loadPermissions(gmp); const loadNotesFunc = loadNotes(gmp); const loadOverridesFunc = loadOverrides(gmp); - return id => dispatch => { - dispatch(loadTaskFunc(id)); - dispatch(loadPermissionsFunc(permissionsResourceFilter(id))); - dispatch(loadNotesFunc(taskIdFilter(id))); - dispatch(loadOverridesFunc(taskIdFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadTaskFunc(id)), + dispatch(loadPermissionsFunc(permissionsResourceFilter(id))), + dispatch(loadNotesFunc(taskIdFilter(id))), + dispatch(loadOverridesFunc(taskIdFilter(id))), + ]); }; export default withEntityContainer('task', { diff --git a/gsa/src/web/pages/users/detailspage.js b/gsa/src/web/pages/users/detailspage.js index eb4a72826a..09bbae7d6f 100644 --- a/gsa/src/web/pages/users/detailspage.js +++ b/gsa/src/web/pages/users/detailspage.js @@ -240,10 +240,10 @@ Page.propTypes = { const load = gmp => { const loadEntityFunc = loadEntity(gmp); const loadPermissionsFunc = loadPermissions(gmp); - return id => dispatch => { - dispatch(loadEntityFunc(id)); - dispatch(loadPermissionsFunc(permissionsSubjectFilter(id))); - }; + return id => dispatch => Promise.all([ + dispatch(loadEntityFunc(id)), + dispatch(loadPermissionsFunc(permissionsSubjectFilter(id))), + ]); }; const mapStateToProps = (rootState, {id}) => { From 513dbd79bac02f7914d591044da522640f83e514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 12:21:27 +0200 Subject: [PATCH 03/17] Start loading timer only if EntitiesContainer is mounted Under some circumstances it may be possible that the timer is started when the component is alread unmounted. E.g. the loading is already running when the component is unmounted. Ensure starting the timer only if it is mounted. --- gsa/src/web/entities/container.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gsa/src/web/entities/container.js b/gsa/src/web/entities/container.js index 8adee33c50..fb4492b9c8 100644 --- a/gsa/src/web/entities/container.js +++ b/gsa/src/web/entities/container.js @@ -131,6 +131,7 @@ class EntitiesContainer extends React.Component { }; componentDidMount() { + this.isRunning = true; const {filter} = this.props.location.query; if (isDefined(filter)) { @@ -144,6 +145,7 @@ class EntitiesContainer extends React.Component { } componentWillUnmount() { + this.isRunning = false; this.clearTimer(); // remove possible running timer } @@ -176,6 +178,10 @@ class EntitiesContainer extends React.Component { } startTimer() { + if (!this.isRunning) { + return; + } + const refresh = this.getRefreshInterval(); if (refresh > 0) { this.timer = global.setTimeout(this.handleTimer, refresh); From 8a1cfa3af28fb4d1d2a1da5e2be08b4c632dc771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 12:32:01 +0200 Subject: [PATCH 04/17] Improve debug message for entities loading timers --- gsa/src/web/entities/container.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gsa/src/web/entities/container.js b/gsa/src/web/entities/container.js index fb4492b9c8..a4f7fc47bd 100644 --- a/gsa/src/web/entities/container.js +++ b/gsa/src/web/entities/container.js @@ -186,13 +186,14 @@ class EntitiesContainer extends React.Component { if (refresh > 0) { this.timer = global.setTimeout(this.handleTimer, refresh); log.debug('Started reload timer with id', this.timer, 'and interval of', - refresh, 'milliseconds'); + refresh, 'milliseconds for', this.props.gmpname); } } clearTimer() { if (isDefined(this.timer)) { - log.debug('Clearing reload timer with id', this.timer); + log.debug('Clearing reload timer with id', this.timer, 'for', + this.props.gmpname); global.clearTimeout(this.timer); } } From e8904cffed55407688252a8a039c9578e9972aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 12:34:18 +0200 Subject: [PATCH 05/17] Adjust entities reload interval if last load was expensive Measure the duration of the last loading procedure and adjust the reload timer if the duration was longer then the to be set reload interval. In that case the new reload interval is calculated from the last duration. The last duration is multiplied with some more or less random value to ensure the timer takes longer then the loading procedure. --- gsa/src/web/entities/container.js | 47 ++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/gsa/src/web/entities/container.js b/gsa/src/web/entities/container.js index a4f7fc47bd..b6bdc101a2 100644 --- a/gsa/src/web/entities/container.js +++ b/gsa/src/web/entities/container.js @@ -60,6 +60,8 @@ const exclude_props = [ 'onDownload', ]; +const LOAD_TIME_FACTOR = 1.2; + class EntitiesContainer extends React.Component { constructor(...args) { @@ -134,6 +136,8 @@ class EntitiesContainer extends React.Component { this.isRunning = true; const {filter} = this.props.location.query; + this.startMeasurement(); + if (isDefined(filter)) { // use filter from url this.load(Filter.fromString(filter)); @@ -172,6 +176,20 @@ class EntitiesContainer extends React.Component { this.load(this.props.filter); } + startMeasurement() { + this.startTimeStamp = performance.now(); + } + + endMeasurement() { + if (!isDefined(this.startTimeStamp)) { + return 0; + } + + const duration = performance.now() - this.startTimeStamp; + this.startTimeStamp = undefined; + return duration; + } + getRefreshInterval() { const {gmp} = this.props; return gmp.autorefresh * 1000; @@ -182,11 +200,21 @@ class EntitiesContainer extends React.Component { return; } - const refresh = this.getRefreshInterval(); - if (refresh > 0) { - this.timer = global.setTimeout(this.handleTimer, refresh); + const loadTime = this.endMeasurement(); + + log.debug('Loading time was', loadTime, 'milliseconds'); + + let interval = this.getRefreshInterval(); + + if (loadTime > interval) { + // ensure timer is longer then the loading procedure + interval = loadTime * LOAD_TIME_FACTOR; + } + + if (interval > 0) { + this.timer = global.setTimeout(this.handleTimer, interval); log.debug('Started reload timer with id', this.timer, 'and interval of', - refresh, 'milliseconds for', this.props.gmpname); + interval, 'milliseconds for', this.props.gmpname); } } @@ -202,13 +230,18 @@ class EntitiesContainer extends React.Component { log.debug('Timer', this.timer, 'finished. Reloading data.'); this.timer = undefined; - this.reload(); + + this.startMeasurement(); + this.notifyTimer(); + this.reload(); } handleChanged() { - this.reload(); + this.startMeasurement(); + this.notifyChanged(); + this.reload(); } handleSelectionTypeChange(selectionType) { @@ -280,8 +313,8 @@ class EntitiesContainer extends React.Component { this.handleInteraction(); promise.then(deleted => { - this.reload(); log.debug('successfully deleted entities', deleted); + this.handleChanged(); }, this.handleError); } From c7d3796833903355461b7f938d304f6d4efbcc37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 12:53:01 +0200 Subject: [PATCH 06/17] Allow to calculate the reload interval from props Allow to provide a reloadInterval function to EntityContainer and EntitiesContainer components. This will allow to calculate the reload interval from pops. --- gsa/src/web/entities/container.js | 10 +++++++++- gsa/src/web/entities/withEntitiesContainer.js | 2 ++ gsa/src/web/entity/container.js | 10 +++++++++- gsa/src/web/entity/withEntityContainer.js | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gsa/src/web/entities/container.js b/gsa/src/web/entities/container.js index b6bdc101a2..2cfc2e1767 100644 --- a/gsa/src/web/entities/container.js +++ b/gsa/src/web/entities/container.js @@ -191,7 +191,14 @@ class EntitiesContainer extends React.Component { } getRefreshInterval() { - const {gmp} = this.props; + const { + gmp, + reloadInterval, + } = this.props; + + if (isDefined(reloadInterval)) { + return reloadInterval(this.props); + } return gmp.autorefresh * 1000; } @@ -692,6 +699,7 @@ EntitiesContainer.propTypes = { loadEntities: PropTypes.func.isRequired, loadedFilter: PropTypes.filter, notify: PropTypes.func.isRequired, + reloadInterval: PropTypes.func, showError: PropTypes.func.isRequired, showErrorMessage: PropTypes.func.isRequired, showSuccessMessage: PropTypes.func.isRequired, diff --git a/gsa/src/web/entities/withEntitiesContainer.js b/gsa/src/web/entities/withEntitiesContainer.js index 087ecf8364..5e24a8fbf2 100644 --- a/gsa/src/web/entities/withEntitiesContainer.js +++ b/gsa/src/web/entities/withEntitiesContainer.js @@ -42,6 +42,7 @@ import EntitiesContainer from './container'; const withEntitiesContainer = (gmpname, { entitiesSelector, loadEntities, + reloadInterval, }) => Component => { let EntitiesContainerWrapper = props => ( @@ -50,6 +51,7 @@ const withEntitiesContainer = (gmpname, { {...props} notify={notify} gmpname={gmpname} + reloadInterval={reloadInterval} > {pageProps => ( Component => { const EntityContainerWrapper = ({id, ...props}) => ( {cprops => } From f80f704dd8f4b01c314dec0dc220c0bb152dacf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 14:14:13 +0200 Subject: [PATCH 07/17] Add a new js utils module for application wide constants Add a first constant for the reload interval if "something" is active. --- gsa/CMakeLists.txt | 1 + gsa/src/web/utils/constants.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gsa/src/web/utils/constants.js diff --git a/gsa/CMakeLists.txt b/gsa/CMakeLists.txt index c155353c14..663f9ba337 100644 --- a/gsa/CMakeLists.txt +++ b/gsa/CMakeLists.txt @@ -823,6 +823,7 @@ set (GSA_JS_SRC_FILES ${GSA_SRC_DIR}/src/web/authorized.js ${GSA_SRC_DIR}/src/web/utils/cert.js ${GSA_SRC_DIR}/src/web/utils/compose.js + ${GSA_SRC_DIR}/src/web/utils/constants.js ${GSA_SRC_DIR}/src/web/utils/cpe.js ${GSA_SRC_DIR}/src/web/utils/globalcss.js ${GSA_SRC_DIR}/src/web/utils/os.js diff --git a/gsa/src/web/utils/constants.js b/gsa/src/web/utils/constants.js new file mode 100644 index 0000000000..9d213d254c --- /dev/null +++ b/gsa/src/web/utils/constants.js @@ -0,0 +1,25 @@ +/* Greenbone Security Assistant + * + * Authors: + * Björn Ricks + * + * Copyright: + * Copyright (C) 2018 Greenbone Networks GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +export const DEFAULT_RELOAD_INTERVAL_ACTIVE = 3 * 1000; // three seconds + +// vim: set ts=2 sw=2 tw=80: From 82888db3b12a9fdda32a4e799bb53aebfe2ab98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 14:24:14 +0200 Subject: [PATCH 08/17] Adjust reload interval if tasks are active Use three seconds reload interval if a task is active at the task details and task list pages. --- gsa/src/web/pages/tasks/detailspage.js | 4 ++++ gsa/src/web/pages/tasks/listpage.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/gsa/src/web/pages/tasks/detailspage.js b/gsa/src/web/pages/tasks/detailspage.js index 81db78d0a9..47c6e59f5a 100644 --- a/gsa/src/web/pages/tasks/detailspage.js +++ b/gsa/src/web/pages/tasks/detailspage.js @@ -89,6 +89,7 @@ import { loadEntity as loadTask, } from 'web/store/entities/tasks'; +import {DEFAULT_RELOAD_INTERVAL_ACTIVE} from 'web/utils/constants'; import PropTypes from 'web/utils/proptypes'; import {renderYesNo} from 'web/utils/render'; import withComponentDefaults from 'web/utils/withComponentDefaults'; @@ -571,6 +572,9 @@ export default withEntityContainer('task', { load, entitySelector: taskSelector, mapStateToProps, + reloadInterval: ({gmp, entity}) => entity.isActive() ? + DEFAULT_RELOAD_INTERVAL_ACTIVE : + gmp.autorefresh, })(Page); // vim: set ts=2 sw=2 tw=80: diff --git a/gsa/src/web/pages/tasks/listpage.js b/gsa/src/web/pages/tasks/listpage.js index 52a4cdaf65..3ca60a2baf 100644 --- a/gsa/src/web/pages/tasks/listpage.js +++ b/gsa/src/web/pages/tasks/listpage.js @@ -46,6 +46,8 @@ import IconDivider from 'web/components/layout/icondivider'; import IconMenu from 'web/components/menu/iconmenu'; import MenuEntry from 'web/components/menu/menuentry'; +import {DEFAULT_RELOAD_INTERVAL_ACTIVE} from 'web/utils/constants'; + import NewIconMenu from './icons/newiconmenu'; import TaskComponent from './component'; @@ -208,9 +210,15 @@ Page.propTypes = { onInteraction: PropTypes.func.isRequired, }; +const taskReloadInterval = (gmp, entities = []) => + entities.some(task => task.isActive()) ? + DEFAULT_RELOAD_INTERVAL_ACTIVE : + gmp.autorefresh * 1000; + export default withEntitiesContainer('task', { entitiesSelector, loadEntities, + reloadInterval: ({gmp, entities}) => taskReloadInterval(gmp, entities), })(Page); // vim: set ts=2 sw=2 tw=80: From bbbc8f952ea31fbef92aa3284683a373cb045b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 14:25:53 +0200 Subject: [PATCH 09/17] Sort imports at reports list page module --- gsa/src/web/pages/reports/listpage.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gsa/src/web/pages/reports/listpage.js b/gsa/src/web/pages/reports/listpage.js index 6677a02065..ef63e4221b 100644 --- a/gsa/src/web/pages/reports/listpage.js +++ b/gsa/src/web/pages/reports/listpage.js @@ -31,10 +31,6 @@ import Filter, {REPORTS_FILTER_FILTER} from 'gmp/models/filter'; import {isDefined} from 'gmp/utils/identity'; import {selectSaveId} from 'gmp/utils/id'; -import compose from 'web/utils/compose'; -import PropTypes from 'web/utils/proptypes'; -import withGmp from 'web/utils/withGmp'; - import EntitiesPage from 'web/entities/page'; import withEntitiesContainer from 'web/entities/withEntitiesContainer'; @@ -52,6 +48,11 @@ import { selector as entitiesSelector, } from 'web/store/entities/reports'; +import {DEFAULT_RELOAD_INTERVAL_ACTIVE} from 'web/utils/constants'; +import compose from 'web/utils/compose'; +import PropTypes from 'web/utils/proptypes'; +import withGmp from 'web/utils/withGmp'; + import ReportFilterDialog from './filterdialog'; import ImportReportDialog from './importdialog'; import ReportsTable from './table'; From 9bad55322bafec8f664b7bf26c6ea4df27aed007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 14:26:54 +0200 Subject: [PATCH 10/17] Adjust reload interval at reports list page dynamically If a corresponding task of a report is active use a three seconds reload interval at the reports list page. --- gsa/src/web/pages/reports/listpage.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gsa/src/web/pages/reports/listpage.js b/gsa/src/web/pages/reports/listpage.js index ef63e4221b..c4452c5523 100644 --- a/gsa/src/web/pages/reports/listpage.js +++ b/gsa/src/web/pages/reports/listpage.js @@ -28,6 +28,8 @@ import _ from 'gmp/locale'; import Filter, {REPORTS_FILTER_FILTER} from 'gmp/models/filter'; +import {isActive} from 'gmp/models/task'; + import {isDefined} from 'gmp/utils/identity'; import {selectSaveId} from 'gmp/utils/id'; @@ -268,11 +270,17 @@ Page.propTypes = { onInteraction: PropTypes.func.isRequired, }; +const reportsReloadInterval = (gmp, entities = []) => + entities.some(entity => isActive(entity.report.scan_run_status)) ? + DEFAULT_RELOAD_INTERVAL_ACTIVE : + gmp.autorefresh * 1000; + export default compose( withGmp, withEntitiesContainer('report', { entitiesSelector, loadEntities, + reloadInterval: ({gmp, entities}) => reportsReloadInterval(gmp, entities), }), )(Page); From 38d00e31e7c501d6ca18ce02a10ec8fc9567e020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 14:30:20 +0200 Subject: [PATCH 11/17] Reduce default reload interval to 15 seconds By default only reload a page every 15 seconds without user input. This reduces the work load at gsad and gvmd. If the reload interval should be reduced the reloadInterval function should be set at the corresponding page instead of lowering the default now. --- gsa/public/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsa/public/config.js b/gsa/public/config.js index 40c89b1c27..3a7db6d2b6 100644 --- a/gsa/public/config.js +++ b/gsa/public/config.js @@ -1,8 +1,8 @@ -const FIVE_SECONDS = 5; +const FIFTEEN_SECONDS = 15; config = { loglevel: 'warn', - autorefresh: FIVE_SECONDS, + autorefresh: FIFTEEN_SECONDS, manualurl: 'http://docs.greenbone.net/GSM-Manual/gos-4/', protocoldocurl: 'http://docs.greenbone.net/API/OMP/omp-7.0.html', }; From 8a73ce916ab6148dc54872059822b5e55b67905b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 15:19:33 +0200 Subject: [PATCH 12/17] Rename autorefresh setting to reloadinterval --- gsa/src/gmp/__tests__/gmpsettings.js | 12 ++++++------ gsa/src/gmp/gmp.js | 8 ++++---- gsa/src/gmp/gmpsettings.js | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gsa/src/gmp/__tests__/gmpsettings.js b/gsa/src/gmp/__tests__/gmpsettings.js index 6ec0281747..a6afdecd9d 100644 --- a/gsa/src/gmp/__tests__/gmpsettings.js +++ b/gsa/src/gmp/__tests__/gmpsettings.js @@ -36,7 +36,7 @@ describe('GmpSettings tests', () => { test('should init with passed options', () => { const storage = createStorage(); const settings = new GmpSettings(storage, { - autorefresh: 10, + reloadinterval: 10, locale: 'en', manualurl: 'http://manual', protocol: 'http', @@ -48,7 +48,7 @@ describe('GmpSettings tests', () => { username: 'foo', }); - expect(settings.autorefresh).toEqual(10); + expect(settings.reloadinterval).toEqual(10); expect(settings.locale).toEqual('en'); expect(settings.manualurl).toEqual('http://manual'); expect(settings.protocol).toEqual('http'); @@ -81,7 +81,7 @@ describe('GmpSettings tests', () => { protocol: 'http', }); - expect(settings.autorefresh).toBeUndefined(); + expect(settings.reloadinterval).toBeUndefined(); expect(settings.locale).toEqual('en'); expect(settings.manualurl).toBeUndefined(); expect(settings.protocol).toEqual('http'); @@ -101,7 +101,7 @@ describe('GmpSettings tests', () => { test('should ensure options override settings from storage', () => { const storage = createStorage({ - autorefresh: 20, + reloadinterval: 20, locale: 'de', manualurl: 'http://ipsum', protocol: 'https', @@ -114,7 +114,7 @@ describe('GmpSettings tests', () => { }); const settings = new GmpSettings(storage, { - autorefresh: 10, + reloadinterval: 10, locale: 'en', manualurl: 'http://manual', protocol: 'http', @@ -126,7 +126,7 @@ describe('GmpSettings tests', () => { username: 'foo', }); - expect(settings.autorefresh).toEqual(10); + expect(settings.reloadinterval).toEqual(10); expect(settings.locale).toEqual('en'); expect(settings.manualurl).toEqual('http://manual'); expect(settings.protocol).toEqual('http'); diff --git a/gsa/src/gmp/gmp.js b/gsa/src/gmp/gmp.js index 11c0cfb210..3249cff6cc 100644 --- a/gsa/src/gmp/gmp.js +++ b/gsa/src/gmp/gmp.js @@ -84,7 +84,7 @@ class Gmp { constructor(options = {}) { const { - autorefresh, + reloadinterval, protocol, server, storage, @@ -96,7 +96,7 @@ class Gmp { log.debug('Using gmp options', options); this.settings = new GmpSettings(storage, { - autorefresh, + reloadinterval, manualurl, protocol, protocoldocurl, @@ -218,8 +218,8 @@ class Gmp { return this; } - get autorefresh() { - return this.settings.autorefresh; + get reloadInterval() { + return this.settings.reloadinterval; } addHttpErrorHandler(handler) { diff --git a/gsa/src/gmp/gmpsettings.js b/gsa/src/gmp/gmpsettings.js index 73acd9ef72..871cc0413c 100644 --- a/gsa/src/gmp/gmpsettings.js +++ b/gsa/src/gmp/gmpsettings.js @@ -34,7 +34,7 @@ const set = (storage, name, value) => { class GmpSettings { constructor(storage = global.localStorage, options = {}) { const { - autorefresh, + reloadinterval, locale, manualurl, protocol = global.location.protocol, @@ -47,7 +47,7 @@ class GmpSettings { } = {...storage, ...options}; this.storage = storage; - this.autorefresh = autorefresh; + this.reloadinterval = reloadinterval; this.locale = locale; this.manualurl = manualurl; this.protocol = protocol; From 77a701fcaf7a8ca602a32afddb3338620092d7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 15:20:13 +0200 Subject: [PATCH 13/17] Provide default for reloadinterval in GmpSettings --- gsa/src/gmp/__tests__/gmpsettings.js | 2 +- gsa/src/gmp/gmpsettings.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gsa/src/gmp/__tests__/gmpsettings.js b/gsa/src/gmp/__tests__/gmpsettings.js index a6afdecd9d..27367edaa5 100644 --- a/gsa/src/gmp/__tests__/gmpsettings.js +++ b/gsa/src/gmp/__tests__/gmpsettings.js @@ -81,7 +81,7 @@ describe('GmpSettings tests', () => { protocol: 'http', }); - expect(settings.reloadinterval).toBeUndefined(); + expect(settings.reloadinterval).toEqual(15000); expect(settings.locale).toEqual('en'); expect(settings.manualurl).toBeUndefined(); expect(settings.protocol).toEqual('http'); diff --git a/gsa/src/gmp/gmpsettings.js b/gsa/src/gmp/gmpsettings.js index 871cc0413c..037126c1af 100644 --- a/gsa/src/gmp/gmpsettings.js +++ b/gsa/src/gmp/gmpsettings.js @@ -22,6 +22,8 @@ */ import {isDefined} from './utils/identity'; +const DEFAULT_RELOAD_INTERVAL = 15 * 1000; // fifteen seconds + const set = (storage, name, value) => { if (isDefined(value)) { storage.setItem(name, value); @@ -34,7 +36,7 @@ const set = (storage, name, value) => { class GmpSettings { constructor(storage = global.localStorage, options = {}) { const { - reloadinterval, + reloadinterval = DEFAULT_RELOAD_INTERVAL, locale, manualurl, protocol = global.location.protocol, From d65d2b61e3e0ec2a7c4cc79b36d57f842d3f954c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 15:20:41 +0200 Subject: [PATCH 14/17] Remove obsolete autorefresh from config file --- gsa/public/config.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/gsa/public/config.js b/gsa/public/config.js index 3a7db6d2b6..ec60ca2ff7 100644 --- a/gsa/public/config.js +++ b/gsa/public/config.js @@ -1,8 +1,5 @@ -const FIFTEEN_SECONDS = 15; - config = { loglevel: 'warn', - autorefresh: FIFTEEN_SECONDS, manualurl: 'http://docs.greenbone.net/GSM-Manual/gos-4/', protocoldocurl: 'http://docs.greenbone.net/API/OMP/omp-7.0.html', }; From 70309add2beda7e467029a3eaa41010e97b946fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 15:22:21 +0200 Subject: [PATCH 15/17] Provide a defaultReloadInterval prop to detail and list pages Use the new prop to calculate the actual reload interval. --- gsa/src/web/entities/container.js | 9 ++++----- gsa/src/web/entities/withEntitiesContainer.js | 3 ++- gsa/src/web/entity/container.js | 9 ++++----- gsa/src/web/entity/withEntityContainer.js | 1 + gsa/src/web/pages/reports/listpage.js | 12 +++++++----- gsa/src/web/pages/tasks/detailspage.js | 4 ++-- gsa/src/web/pages/tasks/listpage.js | 12 +++++++----- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/gsa/src/web/entities/container.js b/gsa/src/web/entities/container.js index 2cfc2e1767..b998643e4a 100644 --- a/gsa/src/web/entities/container.js +++ b/gsa/src/web/entities/container.js @@ -192,14 +192,12 @@ class EntitiesContainer extends React.Component { getRefreshInterval() { const { - gmp, + defaultReloadInterval, reloadInterval, } = this.props; - if (isDefined(reloadInterval)) { - return reloadInterval(this.props); - } - return gmp.autorefresh * 1000; + return isDefined(reloadInterval) ? reloadInterval(this.props) : + defaultReloadInterval; } startTimer() { @@ -688,6 +686,7 @@ class EntitiesContainer extends React.Component { EntitiesContainer.propTypes = { children: PropTypes.func.isRequired, + defaultReloadInterval: PropTypes.number.isRequired, entities: PropTypes.array, entitiesCounts: PropTypes.counts, extraLoadParams: PropTypes.object, diff --git a/gsa/src/web/entities/withEntitiesContainer.js b/gsa/src/web/entities/withEntitiesContainer.js index 5e24a8fbf2..1dcdb2695d 100644 --- a/gsa/src/web/entities/withEntitiesContainer.js +++ b/gsa/src/web/entities/withEntitiesContainer.js @@ -63,12 +63,13 @@ const withEntitiesContainer = (gmpname, { ); - const mapStateToProps = (state, props) => { + const mapStateToProps = (state, {gmp}) => { const eSelector = entitiesSelector(state); const pSelector = getPage(state); const filter = pSelector.getFilter(gmpname); const entities = eSelector.getEntities(filter); return { + defaultReloadInterval: gmp.reloadInterval, entities, entitiesCounts: eSelector.getEntitiesCounts(filter), filter, diff --git a/gsa/src/web/entity/container.js b/gsa/src/web/entity/container.js index b3b01e4da5..49b8576026 100644 --- a/gsa/src/web/entity/container.js +++ b/gsa/src/web/entity/container.js @@ -84,14 +84,12 @@ class EntityContainer extends React.Component { getRefreshInterval() { const { - gmp, + defaultReloadInterval, reloadInterval, } = this.props; - if (isDefined(reloadInterval)) { - return reloadInterval(this.props); - } - return gmp.autorefresh * 1000; + return isDefined(reloadInterval) ? reloadInterval(this.props) : + defaultReloadInterval; } startTimer() { @@ -145,6 +143,7 @@ class EntityContainer extends React.Component { EntityContainer.propTypes = { children: PropTypes.func.isRequired, + defaultReloadInterval: PropTypes.number.isRequired, entityType: PropTypes.string.isRequired, gmp: PropTypes.gmp.isRequired, id: PropTypes.id.isRequired, diff --git a/gsa/src/web/entity/withEntityContainer.js b/gsa/src/web/entity/withEntityContainer.js index 6105da357c..ab4930b0b3 100644 --- a/gsa/src/web/entity/withEntityContainer.js +++ b/gsa/src/web/entity/withEntityContainer.js @@ -88,6 +88,7 @@ const withEntityContainer = (entityType, { }) : undefined; return { isLoading: entitySel.isLoadingEntity(id), + defaultReloadInterval: gmp.reloadInterval, ...otherProps, id, entity: entitySel.getEntity(id), diff --git a/gsa/src/web/pages/reports/listpage.js b/gsa/src/web/pages/reports/listpage.js index c4452c5523..b3724bd1dd 100644 --- a/gsa/src/web/pages/reports/listpage.js +++ b/gsa/src/web/pages/reports/listpage.js @@ -270,17 +270,19 @@ Page.propTypes = { onInteraction: PropTypes.func.isRequired, }; -const reportsReloadInterval = (gmp, entities = []) => - entities.some(entity => isActive(entity.report.scan_run_status)) ? - DEFAULT_RELOAD_INTERVAL_ACTIVE : - gmp.autorefresh * 1000; +const reportsReloadInterval = ({ + entities = [], + defaultReloadInterval, +}) => entities.some(entity => isActive(entity.report.scan_run_status)) ? + DEFAULT_RELOAD_INTERVAL_ACTIVE : + defaultReloadInterval; export default compose( withGmp, withEntitiesContainer('report', { entitiesSelector, loadEntities, - reloadInterval: ({gmp, entities}) => reportsReloadInterval(gmp, entities), + reloadInterval: reportsReloadInterval, }), )(Page); diff --git a/gsa/src/web/pages/tasks/detailspage.js b/gsa/src/web/pages/tasks/detailspage.js index 47c6e59f5a..9c419b97a6 100644 --- a/gsa/src/web/pages/tasks/detailspage.js +++ b/gsa/src/web/pages/tasks/detailspage.js @@ -572,9 +572,9 @@ export default withEntityContainer('task', { load, entitySelector: taskSelector, mapStateToProps, - reloadInterval: ({gmp, entity}) => entity.isActive() ? + reloadInterval: ({defaultReloadInterval, entity}) => entity.isActive() ? DEFAULT_RELOAD_INTERVAL_ACTIVE : - gmp.autorefresh, + defaultReloadInterval, })(Page); // vim: set ts=2 sw=2 tw=80: diff --git a/gsa/src/web/pages/tasks/listpage.js b/gsa/src/web/pages/tasks/listpage.js index 3ca60a2baf..a7c2d8991a 100644 --- a/gsa/src/web/pages/tasks/listpage.js +++ b/gsa/src/web/pages/tasks/listpage.js @@ -210,15 +210,17 @@ Page.propTypes = { onInteraction: PropTypes.func.isRequired, }; -const taskReloadInterval = (gmp, entities = []) => - entities.some(task => task.isActive()) ? - DEFAULT_RELOAD_INTERVAL_ACTIVE : - gmp.autorefresh * 1000; +const taskReloadInterval = ({ + entities = [], + defaultReloadInterval, +}) => entities.some(task => task.isActive()) ? + DEFAULT_RELOAD_INTERVAL_ACTIVE : + defaultReloadInterval; export default withEntitiesContainer('task', { entitiesSelector, loadEntities, - reloadInterval: ({gmp, entities}) => taskReloadInterval(gmp, entities), + reloadInterval: taskReloadInterval, })(Page); // vim: set ts=2 sw=2 tw=80: From 503111ec856419cf32d2c05deba3ae3b6e166b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 15:23:28 +0200 Subject: [PATCH 16/17] Update dashboard pages to use new reloadInterval getter Replace gmp.autorefresh with new gmp.reloadInterval api. --- gsa/src/web/pages/assets/dashboard.js | 2 +- gsa/src/web/pages/reports/detailspage.js | 2 +- gsa/src/web/pages/scans/dashboard.js | 2 +- gsa/src/web/pages/securityinfo/dashboard.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gsa/src/web/pages/assets/dashboard.js b/gsa/src/web/pages/assets/dashboard.js index 38a50b8c57..ae4e67ff7a 100644 --- a/gsa/src/web/pages/assets/dashboard.js +++ b/gsa/src/web/pages/assets/dashboard.js @@ -66,7 +66,7 @@ class AssetsDashboard extends React.Component { getRefreshInterval() { const {gmp} = this.props; - return gmp.autorefresh * 1000; + return gmp.reloadInterval; } startTimer() { diff --git a/gsa/src/web/pages/reports/detailspage.js b/gsa/src/web/pages/reports/detailspage.js index 88b543e275..d465bd6be1 100644 --- a/gsa/src/web/pages/reports/detailspage.js +++ b/gsa/src/web/pages/reports/detailspage.js @@ -285,7 +285,7 @@ class ReportDetails extends React.Component { getRefreshInterval() { const {gmp} = this.props; - return gmp.autorefresh * 1000; + return gmp.reloadInterval; } startTimer(immediate = false) { diff --git a/gsa/src/web/pages/scans/dashboard.js b/gsa/src/web/pages/scans/dashboard.js index bfa0210037..61e6ffde52 100644 --- a/gsa/src/web/pages/scans/dashboard.js +++ b/gsa/src/web/pages/scans/dashboard.js @@ -82,7 +82,7 @@ class ScansDashboard extends React.Component { getRefreshInterval() { const {gmp} = this.props; - return gmp.autorefresh * 1000; + return gmp.reloadInterval; } startTimer() { diff --git a/gsa/src/web/pages/securityinfo/dashboard.js b/gsa/src/web/pages/securityinfo/dashboard.js index 5c94717378..dd20af2fa1 100644 --- a/gsa/src/web/pages/securityinfo/dashboard.js +++ b/gsa/src/web/pages/securityinfo/dashboard.js @@ -70,7 +70,7 @@ class SecurityInfoDashboard extends React.Component { getRefreshInterval() { const {gmp} = this.props; - return gmp.autorefresh * 1000; + return gmp.reloadInterval; } startTimer() { From 7e0c820f5714c52111bbccb7431ed969a91e5c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 5 Sep 2018 15:26:52 +0200 Subject: [PATCH 17/17] Rename getRefreshInterval into getReloadInterval --- gsa/src/web/entities/container.js | 4 ++-- gsa/src/web/entity/container.js | 4 ++-- gsa/src/web/pages/assets/dashboard.js | 10 +++++----- gsa/src/web/pages/scans/dashboard.js | 10 +++++----- gsa/src/web/pages/securityinfo/dashboard.js | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gsa/src/web/entities/container.js b/gsa/src/web/entities/container.js index b998643e4a..f982c0bf0d 100644 --- a/gsa/src/web/entities/container.js +++ b/gsa/src/web/entities/container.js @@ -190,7 +190,7 @@ class EntitiesContainer extends React.Component { return duration; } - getRefreshInterval() { + getReloadInterval() { const { defaultReloadInterval, reloadInterval, @@ -209,7 +209,7 @@ class EntitiesContainer extends React.Component { log.debug('Loading time was', loadTime, 'milliseconds'); - let interval = this.getRefreshInterval(); + let interval = this.getReloadInterval(); if (loadTime > interval) { // ensure timer is longer then the loading procedure diff --git a/gsa/src/web/entity/container.js b/gsa/src/web/entity/container.js index 49b8576026..9945f034c0 100644 --- a/gsa/src/web/entity/container.js +++ b/gsa/src/web/entity/container.js @@ -82,7 +82,7 @@ class EntityContainer extends React.Component { this.reload(); } - getRefreshInterval() { + getReloadInterval() { const { defaultReloadInterval, reloadInterval, @@ -97,7 +97,7 @@ class EntityContainer extends React.Component { return; } - const interval = this.getRefreshInterval(); + const interval = this.getReloadInterval(); if (interval > 0) { this.timer = global.setTimeout(this.handleTimer, interval); diff --git a/gsa/src/web/pages/assets/dashboard.js b/gsa/src/web/pages/assets/dashboard.js index ae4e67ff7a..6ba0c541e6 100644 --- a/gsa/src/web/pages/assets/dashboard.js +++ b/gsa/src/web/pages/assets/dashboard.js @@ -64,17 +64,17 @@ class AssetsDashboard extends React.Component { this.clearTimer(); } - getRefreshInterval() { + getReloadInterval() { const {gmp} = this.props; return gmp.reloadInterval; } startTimer() { - const refresh = this.getRefreshInterval(); - if (refresh >= 0) { - this.timer = window.setTimeout(this.handleTimer, refresh); + const interval = this.getReloadInterval(); + if (interval > 0) { + this.timer = window.setTimeout(this.handleTimer, interval); log.debug('Started reload timer with id', this.timer, 'and interval of', - refresh, 'milliseconds'); + interval, 'milliseconds'); } } diff --git a/gsa/src/web/pages/scans/dashboard.js b/gsa/src/web/pages/scans/dashboard.js index 61e6ffde52..33daead37f 100644 --- a/gsa/src/web/pages/scans/dashboard.js +++ b/gsa/src/web/pages/scans/dashboard.js @@ -80,17 +80,17 @@ class ScansDashboard extends React.Component { this.clearTimer(); } - getRefreshInterval() { + getReloadInterval() { const {gmp} = this.props; return gmp.reloadInterval; } startTimer() { - const refresh = this.getRefreshInterval(); - if (refresh >= 0) { - this.timer = window.setTimeout(this.handleTimer, refresh); + const interval = this.getReloadInterval(); + if (interval > 0) { + this.timer = window.setTimeout(this.handleTimer, interval); log.debug('Started reload timer with id', this.timer, 'and interval of', - refresh, 'milliseconds'); + interval, 'milliseconds'); } } diff --git a/gsa/src/web/pages/securityinfo/dashboard.js b/gsa/src/web/pages/securityinfo/dashboard.js index dd20af2fa1..ba6e1e361c 100644 --- a/gsa/src/web/pages/securityinfo/dashboard.js +++ b/gsa/src/web/pages/securityinfo/dashboard.js @@ -68,17 +68,17 @@ class SecurityInfoDashboard extends React.Component { this.clearTimer(); } - getRefreshInterval() { + getReloadInterval() { const {gmp} = this.props; return gmp.reloadInterval; } startTimer() { - const refresh = this.getRefreshInterval(); - if (refresh >= 0) { - this.timer = window.setTimeout(this.handleTimer, refresh); + const interval = this.getReloadInterval(); + if (interval >= 0) { + this.timer = window.setTimeout(this.handleTimer, interval); log.debug('Started reload timer with id', this.timer, 'and interval of', - refresh, 'milliseconds'); + interval, 'milliseconds'); } }