Skip to content

Commit 30f95e5

Browse files
authored
! Fix persistent cache incorrectly having higher priority then auto fetch feed option on new window open (#5743)
1 parent 4503ff1 commit 30f95e5

File tree

5 files changed

+132
-53
lines changed

5 files changed

+132
-53
lines changed

src/renderer/components/subscriptions-community/subscriptions-community.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,23 @@ export default defineComponent({
101101
},
102102
},
103103
mounted: async function () {
104-
this.loadPostsFromCacheSometimes()
104+
this.loadPostsFromRemoteFirstPerWindowSometimes()
105105
},
106106
methods: {
107+
loadPostsFromRemoteFirstPerWindowSometimes() {
108+
if (!this.fetchSubscriptionsAutomatically) {
109+
this.loadPostsFromCacheSometimes()
110+
return
111+
}
112+
if (this.$store.getters.getSubscriptionForCommunityPostsFirstAutoFetchRun) {
113+
// Only auto fetch once per window
114+
this.loadPostsFromCacheSometimes()
115+
return
116+
}
117+
118+
this.loadPostsForSubscriptionsFromRemote()
119+
this.$store.commit('setSubscriptionForCommunityPostsFirstAutoFetchRun')
120+
},
107121
loadPostsFromCacheSometimes() {
108122
// Can only load reliably when cache ready
109123
if (!this.subscriptionCacheReady) { return }
@@ -114,7 +128,15 @@ export default defineComponent({
114128
return
115129
}
116130

117-
this.maybeLoadPostsForSubscriptionsFromRemote()
131+
if (this.fetchSubscriptionsAutomatically) {
132+
// `this.isLoading = false` is called inside `loadPostsForSubscriptionsFromRemote` when needed
133+
this.loadPostsForSubscriptionsFromRemote()
134+
return
135+
}
136+
137+
this.postList = []
138+
this.attemptedFetch = false
139+
this.isLoading = false
118140
},
119141

120142
async loadPostsFromCacheForAllActiveProfileChannels() {
@@ -201,17 +223,6 @@ export default defineComponent({
201223
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
202224
},
203225

204-
maybeLoadPostsForSubscriptionsFromRemote: async function () {
205-
if (this.fetchSubscriptionsAutomatically) {
206-
// `this.isLoading = false` is called inside `loadPostsForSubscriptionsFromRemote` when needed
207-
await this.loadPostsForSubscriptionsFromRemote()
208-
} else {
209-
this.postList = []
210-
this.attemptedFetch = false
211-
this.isLoading = false
212-
}
213-
},
214-
215226
getChannelPostsLocal: async function (channel) {
216227
try {
217228
const entries = await getLocalChannelCommunity(channel.id)

src/renderer/components/subscriptions-live/subscriptions-live.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,23 @@ export default defineComponent({
111111
},
112112
},
113113
mounted: async function () {
114-
this.loadVideosFromCacheSometimes()
114+
this.loadVideosFromRemoteFirstPerWindowSometimes()
115115
},
116116
methods: {
117+
loadVideosFromRemoteFirstPerWindowSometimes() {
118+
if (!this.fetchSubscriptionsAutomatically) {
119+
this.loadVideosFromCacheSometimes()
120+
return
121+
}
122+
if (this.$store.getters.getSubscriptionForLiveStreamsFirstAutoFetchRun) {
123+
// Only auto fetch once per window
124+
this.loadVideosFromCacheSometimes()
125+
return
126+
}
127+
128+
this.loadVideosForSubscriptionsFromRemote()
129+
this.$store.commit('setSubscriptionForLiveStreamsFirstAutoFetchRun')
130+
},
117131
loadVideosFromCacheSometimes() {
118132
// Can only load reliably when cache ready
119133
if (!this.subscriptionCacheReady) { return }
@@ -124,7 +138,16 @@ export default defineComponent({
124138
return
125139
}
126140

127-
this.maybeLoadVideosForSubscriptionsFromRemote()
141+
if (this.fetchSubscriptionsAutomatically) {
142+
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
143+
this.loadVideosForSubscriptionsFromRemote()
144+
return
145+
}
146+
147+
// Auto fetch disabled, not enough cache for profile = show nothing
148+
this.videoList = []
149+
this.attemptedFetch = false
150+
this.isLoading = false
128151
},
129152

130153
async loadVideosFromCacheForAllActiveProfileChannels() {
@@ -207,17 +230,6 @@ export default defineComponent({
207230
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
208231
},
209232

210-
maybeLoadVideosForSubscriptionsFromRemote: async function () {
211-
if (this.fetchSubscriptionsAutomatically) {
212-
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
213-
await this.loadVideosForSubscriptionsFromRemote()
214-
} else {
215-
this.videoList = []
216-
this.attemptedFetch = false
217-
this.isLoading = false
218-
}
219-
},
220-
221233
getChannelLiveLocal: async function (channel, failedAttempts = 0) {
222234
try {
223235
const result = await getLocalChannelLiveStreams(channel.id)

src/renderer/components/subscriptions-shorts/subscriptions-shorts.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,23 @@ export default defineComponent({
105105
},
106106
},
107107
mounted: async function () {
108-
this.loadVideosFromCacheSometimes()
108+
this.loadVideosFromRemoteFirstPerWindowSometimes()
109109
},
110110
methods: {
111+
loadVideosFromRemoteFirstPerWindowSometimes() {
112+
if (!this.fetchSubscriptionsAutomatically) {
113+
this.loadVideosFromCacheSometimes()
114+
return
115+
}
116+
if (this.$store.getters.getSubscriptionForShortsFirstAutoFetchRun) {
117+
// Only auto fetch once per window
118+
this.loadVideosFromCacheSometimes()
119+
return
120+
}
121+
122+
this.loadVideosForSubscriptionsFromRemote()
123+
this.$store.commit('setSubscriptionForShortsFirstAutoFetchRun')
124+
},
111125
loadVideosFromCacheSometimes() {
112126
// Can only load reliably when cache ready
113127
if (!this.subscriptionCacheReady) { return }
@@ -118,7 +132,16 @@ export default defineComponent({
118132
return
119133
}
120134

121-
this.maybeLoadVideosForSubscriptionsFromRemote()
135+
if (this.fetchSubscriptionsAutomatically) {
136+
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
137+
this.loadVideosForSubscriptionsFromRemote()
138+
return
139+
}
140+
141+
// Auto fetch disabled, not enough cache for profile = show nothing
142+
this.videoList = []
143+
this.attemptedFetch = false
144+
this.isLoading = false
122145
},
123146

124147
async loadVideosFromCacheForAllActiveProfileChannels() {
@@ -183,17 +206,6 @@ export default defineComponent({
183206
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
184207
},
185208

186-
maybeLoadVideosForSubscriptionsFromRemote: async function () {
187-
if (this.fetchSubscriptionsAutomatically) {
188-
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
189-
await this.loadVideosForSubscriptionsFromRemote()
190-
} else {
191-
this.videoList = []
192-
this.attemptedFetch = false
193-
this.isLoading = false
194-
}
195-
},
196-
197209
getChannelShortsLocal: async function (channel, failedAttempts = 0) {
198210
const playlistId = getChannelPlaylistId(channel.id, 'shorts', 'newest')
199211
const feedUrl = `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}`

src/renderer/components/subscriptions-videos/subscriptions-videos.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,23 @@ export default defineComponent({
115115
},
116116
},
117117
mounted: async function () {
118-
this.loadVideosFromCacheSometimes()
118+
this.loadVideosFromRemoteFirstPerWindowSometimes()
119119
},
120120
methods: {
121+
loadVideosFromRemoteFirstPerWindowSometimes() {
122+
if (!this.fetchSubscriptionsAutomatically) {
123+
this.loadVideosFromCacheSometimes()
124+
return
125+
}
126+
if (this.$store.getters.getSubscriptionForVideosFirstAutoFetchRun) {
127+
// Only auto fetch once per window
128+
this.loadVideosFromCacheSometimes()
129+
return
130+
}
131+
132+
this.loadVideosForSubscriptionsFromRemote()
133+
this.$store.commit('setSubscriptionForVideosFirstAutoFetchRun')
134+
},
121135
loadVideosFromCacheSometimes() {
122136
// Can only load reliably when cache ready
123137
if (!this.subscriptionCacheReady) { return }
@@ -128,7 +142,16 @@ export default defineComponent({
128142
return
129143
}
130144

131-
this.maybeLoadVideosForSubscriptionsFromRemote()
145+
if (this.fetchSubscriptionsAutomatically) {
146+
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
147+
this.loadVideosForSubscriptionsFromRemote()
148+
return
149+
}
150+
151+
// Auto fetch disabled, not enough cache for profile = show nothing
152+
this.videoList = []
153+
this.attemptedFetch = false
154+
this.isLoading = false
132155
},
133156

134157
async loadVideosFromCacheForAllActiveProfileChannels() {
@@ -211,17 +234,6 @@ export default defineComponent({
211234
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
212235
},
213236

214-
maybeLoadVideosForSubscriptionsFromRemote: async function () {
215-
if (this.fetchSubscriptionsAutomatically) {
216-
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
217-
await this.loadVideosForSubscriptionsFromRemote()
218-
} else {
219-
this.videoList = []
220-
this.attemptedFetch = false
221-
this.isLoading = false
222-
}
223-
},
224-
225237
getChannelVideosLocalScraper: async function (channel, failedAttempts = 0) {
226238
try {
227239
const result = await getLocalChannelVideos(channel.id)

src/renderer/store/modules/utils.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ const state = {
5858
lastCommunityRefreshTimestampByProfile: {},
5959
lastPopularRefreshTimestamp: '',
6060
lastTrendingRefreshTimestamp: '',
61+
subscriptionFirstAutoFetchRunData: {
62+
videos: false,
63+
liveStreams: false,
64+
shorts: false,
65+
communityPosts: false,
66+
},
6167
}
6268

6369
const getters = {
@@ -164,6 +170,19 @@ const getters = {
164170
getLastPopularRefreshTimestamp(state) {
165171
return state.lastPopularRefreshTimestamp
166172
},
173+
174+
getSubscriptionForVideosFirstAutoFetchRun(state) {
175+
return state.subscriptionFirstAutoFetchRunData.videos === true
176+
},
177+
getSubscriptionForLiveStreamsFirstAutoFetchRun (state) {
178+
return state.subscriptionFirstAutoFetchRunData.liveStreams === true
179+
},
180+
getSubscriptionForShortsFirstAutoFetchRun (state) {
181+
return state.subscriptionFirstAutoFetchRunData.shorts === true
182+
},
183+
getSubscriptionForCommunityPostsFirstAutoFetchRun (state) {
184+
return state.subscriptionFirstAutoFetchRunData.communityPosts === true
185+
},
167186
}
168187

169188
const actions = {
@@ -944,7 +963,20 @@ const mutations = {
944963

945964
setExternalPlayerCmdArguments (state, value) {
946965
state.externalPlayerCmdArguments = value
947-
}
966+
},
967+
968+
setSubscriptionForVideosFirstAutoFetchRun (state) {
969+
state.subscriptionFirstAutoFetchRunData.videos = true
970+
},
971+
setSubscriptionForLiveStreamsFirstAutoFetchRun (state) {
972+
state.subscriptionFirstAutoFetchRunData.liveStreams = true
973+
},
974+
setSubscriptionForShortsFirstAutoFetchRun (state) {
975+
state.subscriptionFirstAutoFetchRunData.shorts = true
976+
},
977+
setSubscriptionForCommunityPostsFirstAutoFetchRun (state) {
978+
state.subscriptionFirstAutoFetchRunData.communityPosts = true
979+
},
948980
}
949981

950982
export default {

0 commit comments

Comments
 (0)