From 19d15a9528aa42e85235fc9344281a285590f937 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Mon, 6 Jul 2020 10:27:31 +0200 Subject: [PATCH] Load backups only when needed for netwrok in restoring state --- src/_store/networks.module.js | 9 +-------- src/account/NetworkPage.vue | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/_store/networks.module.js b/src/_store/networks.module.js index e8099ce..96ce86b 100644 --- a/src/_store/networks.module.js +++ b/src/_store/networks.module.js @@ -48,14 +48,7 @@ const actions = { commit('getNetworkByIdRequest'); networkService.getNetworkById(userId, networkId, messages, errors) .then(network => commit('getNetworkByIdSuccess', network), - error => commit('getNetworkByIdFailure', error)) - .then(() => { - if (state.network.state != 'starting' || state.backups === null) { - dispatch('getBackups', - { userId: userId, networkId: networkId, - messages: messages, errors: errors }); - } - }); + error => commit('getNetworkByIdFailure', error)); }, addPlanAndStartNetwork({ commit }, {userId, accountPlan, cloud, region, messages, errors}) { diff --git a/src/account/NetworkPage.vue b/src/account/NetworkPage.vue index f7a634b..9ab774c 100644 --- a/src/account/NetworkPage.vue +++ b/src/account/NetworkPage.vue @@ -278,7 +278,7 @@ ...mapActions('networks', [ 'getNetworkById', 'deleteNetwork', 'getStatusesByNetworkId', 'getNodesByNetworkId', 'stopNetwork', 'queueBackup', 'restoreNetwork', 'deleteNetwork', 'requestNetworkKeys', - 'retrieveNetworkKeys' + 'retrieveNetworkKeys', 'getBackups' ]), ...mapActions('system', ['getAppLinks']), refreshStatus (userId) { @@ -296,11 +296,23 @@ messages: this.messages, errors: this.errors }); + if (this.backups === null || this.refresher === null) { + // note about the second part of the condition above: if refreshes is turned on, then fetch backups + // from BE only once + this.getBackups({ userId: userId, networkId: this.networkId, + messages: this.messages, errors: this.errors }); + } }, startStatusRefresher (user) { // todo: separate refresher for network -- after "stop" we should refresh the status to show it is stopped this.refresher = setInterval(() => this.refreshStatus(user.uuid), 5000); }, + stopStatusRefresher () { + if (this.refresher !== null) { + clearInterval(this.refresher); + this.refresher = null; + } + }, stopNet () { this.errors.clear(); this.stopNetwork({ @@ -366,13 +378,13 @@ this.getAppLinks(user.locale); }, beforeDestroy () { - clearInterval(this.refresher); + stopStatusRefresher(this.refresher); }, watch: { network (net) { if (net) { if (net.state === 'running' || net.state === 'stopped' || net.state === 'error_stopping' || net.uuid === 'Not Found') { - clearInterval(this.refresher); + stopStatusRefresher(this.refresher); } if (net.uuid === 'Not Found') { this.$router.replace({path: '/bubbles'}); @@ -393,10 +405,10 @@ } if (latestStats !== null) { this.stats = latestStats; - if (this.stats.percent === 100) clearInterval(this.refresher); + if (this.stats.percent === 100) stopStatusRefresher(this.refresher); } else { // status not found for our network - clearInterval(this.refresher); + stopStatusRefresher(this.refresher); } } },