Merge pull request 'polls: don't continuously refresh closed polls and refresh less frequently' (#472) from Oneric/akkoma-fe:poll-upd-frequency-reduction into develop
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #472
This commit is contained in:
commit
34e4928754
1 changed files with 10 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { merge } from 'lodash'
|
||||
|
||||
const POLL_UPDATE_FREQUENCY = 150_000;
|
||||
|
||||
const polls = {
|
||||
state: {
|
||||
// Contains key = id, value = number of trackers for this poll
|
||||
|
|
@ -12,6 +14,9 @@ const polls = {
|
|||
// Make expired-state change trigger re-renders properly
|
||||
poll.expired = Date.now() > Date.parse(poll.expires_at)
|
||||
if (existingPoll) {
|
||||
if (poll.expired) {
|
||||
state.trackedPolls[poll.id] = 0
|
||||
}
|
||||
state.pollsObject[poll.id] = merge(existingPoll, poll)
|
||||
} else {
|
||||
state.pollsObject[poll.id] = poll
|
||||
|
|
@ -44,13 +49,16 @@ const polls = {
|
|||
if (rootState.polls.trackedPolls[pollId]) {
|
||||
dispatch('updateTrackedPoll', pollId)
|
||||
}
|
||||
}, 30 * 1000)
|
||||
}, POLL_UPDATE_FREQUENCY)
|
||||
commit('mergeOrAddPoll', poll)
|
||||
})
|
||||
},
|
||||
trackPoll ({ rootState, commit, dispatch }, pollId) {
|
||||
if (rootState.polls.pollsObject[pollId]?.expired)
|
||||
return;
|
||||
|
||||
if (!rootState.polls.trackedPolls[pollId]) {
|
||||
setTimeout(() => dispatch('updateTrackedPoll', pollId), 30 * 1000)
|
||||
setTimeout(() => dispatch('updateTrackedPoll', pollId), POLL_UPDATE_FREQUENCY)
|
||||
}
|
||||
commit('trackPoll', pollId)
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue