Skip to content

Commit

Permalink
Consolidate clear subscriptions cache into one mutation (#5202)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jun 1, 2024
1 parent 18b3af7 commit a8a0106
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/renderer/store/modules/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ const actions = {
commit('updatePostsCacheByChannel', payload)
},

clearSubscriptionsCache: ({ commit }, payload) => {
commit('clearVideoCache', payload)
commit('clearShortsCache', payload)
commit('clearLiveCache', payload)
commit('clearPostsCache', payload)
clearSubscriptionsCache: ({ commit }) => {
commit('clearCaches')
},
}

Expand All @@ -76,9 +73,6 @@ const mutations = {
newObject.timestamp = timestamp
state.videoCache[channelId] = newObject
},
clearVideoCache(state) {
state.videoCache = {}
},
updateShortsCacheByChannel(state, { channelId, videos, timestamp = new Date() }) {
const existingObject = state.shortsCache[channelId]
const newObject = existingObject ?? { videos: null }
Expand Down Expand Up @@ -111,29 +105,27 @@ const mutations = {
})
}
},
clearShortsCache(state) {
state.shortsCache = {}
},
updateLiveCacheByChannel(state, { channelId, videos, timestamp = new Date() }) {
const existingObject = state.liveCache[channelId]
const newObject = existingObject ?? { videos: null }
if (videos != null) { newObject.videos = videos }
newObject.timestamp = timestamp
state.liveCache[channelId] = newObject
},
clearLiveCache(state) {
state.liveCache = {}
},
updatePostsCacheByChannel(state, { channelId, posts, timestamp = new Date() }) {
const existingObject = state.postsCache[channelId]
const newObject = existingObject ?? { posts: null }
if (posts != null) { newObject.posts = posts }
newObject.timestamp = timestamp
state.postsCache[channelId] = newObject
},
clearPostsCache(state) {

clearCaches(state) {
state.videoCache = {}
state.shortsCache = {}
state.liveCache = {}
state.postsCache = {}
},
}
}

export default {
Expand Down

0 comments on commit a8a0106

Please sign in to comment.