Skip to content

Commit

Permalink
Merge pull request #307 from raffis/fix-reload-delete
Browse files Browse the repository at this point in the history
Fixes high cpu load and blocking browser during multi actions
  • Loading branch information
satterly authored Apr 16, 2020
2 parents 71ba7c4 + 02b0787 commit fa2dbaf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
30 changes: 20 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,10 @@ export default {
this.$store.dispatch('alerts/updateSelected', [])
},
takeBulkAction(action) {
this.selected.map(a => this.$store.dispatch('alerts/takeAction', [a.id, action, '']))
.reduce(() => this.clearSelected())
Promise.all(this.selected.map(a => this.$store.dispatch('alerts/takeAction', [a.id, action, '']))).then(() => {
this.clearSelected()
this.$store.dispatch('alerts/getAlerts')
})
},
bulkAckAlert() {
this.selected.map(a => {
Expand All @@ -711,29 +713,35 @@ export default {
.reduce(() => this.clearSelected())
},
bulkShelveAlert() {
this.selected.map(a => {
Promise.all(this.selected.map(a => {
this.$store
.dispatch('alerts/takeAction', [
a.id,
'shelve',
'',
this.shelveTimeout
])
})).then(() => {
this.clearSelected()
this.$store.dispatch('alerts/getAlerts')
})
.reduce(() => this.clearSelected())
},
isWatched(tags) {
const tag = `watch:${this.username}`
return tags ? tags.indexOf(tag) > -1 : false
},
toggleWatch() {
var map
if (this.selected.some(x => !this.isWatched(x.tags))) {
this.selected.map(a => this.watchAlert(a.id))
.reduce(() => this.clearSelected())
map = this.selected.map(a => this.watchAlert(a.id))
} else {
this.selected.map(a => this.unwatchAlert(a.id))
.reduce(() => this.clearSelected())
map = this.selected.map(a => this.unwatchAlert(a.id))
}
Promise.all(map).then(() => {
this.clearSelected()
this.$store.dispatch('alerts/getAlerts')
})
},
watchAlert(id) {
this.$store.dispatch('alerts/watchAlert', id)
Expand All @@ -743,8 +751,10 @@ export default {
},
bulkDeleteAlert() {
confirm(i18n.t('ConfirmDelete')) &&
this.selected.map(a => this.$store.dispatch('alerts/deleteAlert', a.id))
.reduce(() => this.clearSelected())
Promise.all(this.selected.map(a => this.$store.dispatch('alerts/deleteAlert', a.id, false))).then(() => {
this.clearSelected()
this.$store.dispatch('alerts/getAlerts')
})
},
toggle(sw, value) {
this.$store.dispatch('alerts/toggle', [sw, value])
Expand Down
16 changes: 12 additions & 4 deletions src/components/AlertList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ export default {
},
takeAction: debounce(function(id, action) {
this.$store
.dispatch('alerts/takeAction', [id, action, ''])
.dispatch('alerts/takeAction', [id, action, '']).then(() => {
this.$store.dispatch('alerts/getAlerts')
})
}, 200, {leading: true, trailing: false}),
ackAlert: debounce(function(id) {
this.$store
Expand All @@ -639,15 +641,21 @@ export default {
}, 200, {leading: true, trailing: false}),
watchAlert: debounce(function(id) {
this.$store
.dispatch('alerts/watchAlert', id)
.dispatch('alerts/watchAlert', id).then(() => {
this.$store.dispatch('alerts/getAlerts')
})
}, 200, {leading: true, trailing: false}),
unwatchAlert: debounce(function(id) {
this.$store
.dispatch('alerts/unwatchAlert', id)
.dispatch('alerts/unwatchAlert', id).then(() => {
this.$store.dispatch('alerts/getAlerts')
})
}, 200, {leading: true, trailing: false}),
deleteAlert: debounce(function(id) {
confirm(i18n.t('ConfirmDelete')) &&
this.$store.dispatch('alerts/deleteAlert', id)
this.$store.dispatch('alerts/deleteAlert', id).then(() => {
this.$store.dispatch('alerts/getAlerts')
})
}, 200, {leading: true, trailing: false}),
}
}
Expand Down
22 changes: 6 additions & 16 deletions src/store/modules/alerts.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,25 @@ const actions = {
watchAlert({ commit, dispatch, rootState}, alertId) {
const username = rootState.auth.payload.preferred_username
const tag = `watch:${username}`
return AlertsApi.tagAlert(alertId, {tags: [tag]}).then(response =>
dispatch('getAlerts')
)
return AlertsApi.tagAlert(alertId, {tags: [tag]})
},
unwatchAlert({ commit, dispatch, rootState}, alertId) {
const username = rootState.auth.payload.preferred_username
const tag = `watch:${username}`
return AlertsApi.untagAlert(alertId, {tags: [tag]}).then(response =>
dispatch('getAlerts')
)
return AlertsApi.untagAlert(alertId, {tags: [tag]})
},
takeAction({ commit, dispatch }, [alertId, action, text, timeout]) {
return AlertsApi.actionAlert(alertId, {
action: action,
text: text,
timeout: timeout
}).then(response => dispatch('getAlerts'))
})
},
tagAlert({ commit, dispatch }, [alertId, tags]) {
return AlertsApi.tagAlert(alertId, tags).then(response =>
dispatch('getAlerts')
)
return AlertsApi.tagAlert(alertId, tags)
},
untagAlert({ commit, dispatch }, [alertId, tags]) {
return AlertsApi.untagAlert(alertId, tags).then(response =>
dispatch('getAlerts')
)
return AlertsApi.untagAlert(alertId, tags)
},

addNote({ commit, dispatch }, [alertId, note]) {
Expand All @@ -229,9 +221,7 @@ const actions = {
},

deleteAlert({ commit, dispatch }, alertId) {
return AlertsApi.deleteAlert(alertId).then(response =>
dispatch('getAlerts')
)
return AlertsApi.deleteAlert(alertId)
},

getEnvironments({ commit }) {
Expand Down

0 comments on commit fa2dbaf

Please sign in to comment.