Skip to content

Commit

Permalink
! Fix persistent cache incorrectly having higher priority then auto f…
Browse files Browse the repository at this point in the history
…etch feed option on new window open (#5743)
  • Loading branch information
PikachuEXE authored Sep 28, 2024
1 parent 4503ff1 commit 30f95e5
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,23 @@ export default defineComponent({
},
},
mounted: async function () {
this.loadPostsFromCacheSometimes()
this.loadPostsFromRemoteFirstPerWindowSometimes()
},
methods: {
loadPostsFromRemoteFirstPerWindowSometimes() {
if (!this.fetchSubscriptionsAutomatically) {
this.loadPostsFromCacheSometimes()
return
}
if (this.$store.getters.getSubscriptionForCommunityPostsFirstAutoFetchRun) {
// Only auto fetch once per window
this.loadPostsFromCacheSometimes()
return
}

this.loadPostsForSubscriptionsFromRemote()
this.$store.commit('setSubscriptionForCommunityPostsFirstAutoFetchRun')
},
loadPostsFromCacheSometimes() {
// Can only load reliably when cache ready
if (!this.subscriptionCacheReady) { return }
Expand All @@ -114,7 +128,15 @@ export default defineComponent({
return
}

this.maybeLoadPostsForSubscriptionsFromRemote()
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadPostsForSubscriptionsFromRemote` when needed
this.loadPostsForSubscriptionsFromRemote()
return
}

this.postList = []
this.attemptedFetch = false
this.isLoading = false
},

async loadPostsFromCacheForAllActiveProfileChannels() {
Expand Down Expand Up @@ -201,17 +223,6 @@ export default defineComponent({
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
},

maybeLoadPostsForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadPostsForSubscriptionsFromRemote` when needed
await this.loadPostsForSubscriptionsFromRemote()
} else {
this.postList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelPostsLocal: async function (channel) {
try {
const entries = await getLocalChannelCommunity(channel.id)
Expand Down
38 changes: 25 additions & 13 deletions src/renderer/components/subscriptions-live/subscriptions-live.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,23 @@ export default defineComponent({
},
},
mounted: async function () {
this.loadVideosFromCacheSometimes()
this.loadVideosFromRemoteFirstPerWindowSometimes()
},
methods: {
loadVideosFromRemoteFirstPerWindowSometimes() {
if (!this.fetchSubscriptionsAutomatically) {
this.loadVideosFromCacheSometimes()
return
}
if (this.$store.getters.getSubscriptionForLiveStreamsFirstAutoFetchRun) {
// Only auto fetch once per window
this.loadVideosFromCacheSometimes()
return
}

this.loadVideosForSubscriptionsFromRemote()
this.$store.commit('setSubscriptionForLiveStreamsFirstAutoFetchRun')
},
loadVideosFromCacheSometimes() {
// Can only load reliably when cache ready
if (!this.subscriptionCacheReady) { return }
Expand All @@ -124,7 +138,16 @@ export default defineComponent({
return
}

this.maybeLoadVideosForSubscriptionsFromRemote()
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
this.loadVideosForSubscriptionsFromRemote()
return
}

// Auto fetch disabled, not enough cache for profile = show nothing
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
},

async loadVideosFromCacheForAllActiveProfileChannels() {
Expand Down Expand Up @@ -207,17 +230,6 @@ export default defineComponent({
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
},

maybeLoadVideosForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
await this.loadVideosForSubscriptionsFromRemote()
} else {
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelLiveLocal: async function (channel, failedAttempts = 0) {
try {
const result = await getLocalChannelLiveStreams(channel.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,23 @@ export default defineComponent({
},
},
mounted: async function () {
this.loadVideosFromCacheSometimes()
this.loadVideosFromRemoteFirstPerWindowSometimes()
},
methods: {
loadVideosFromRemoteFirstPerWindowSometimes() {
if (!this.fetchSubscriptionsAutomatically) {
this.loadVideosFromCacheSometimes()
return
}
if (this.$store.getters.getSubscriptionForShortsFirstAutoFetchRun) {
// Only auto fetch once per window
this.loadVideosFromCacheSometimes()
return
}

this.loadVideosForSubscriptionsFromRemote()
this.$store.commit('setSubscriptionForShortsFirstAutoFetchRun')
},
loadVideosFromCacheSometimes() {
// Can only load reliably when cache ready
if (!this.subscriptionCacheReady) { return }
Expand All @@ -118,7 +132,16 @@ export default defineComponent({
return
}

this.maybeLoadVideosForSubscriptionsFromRemote()
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
this.loadVideosForSubscriptionsFromRemote()
return
}

// Auto fetch disabled, not enough cache for profile = show nothing
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
},

async loadVideosFromCacheForAllActiveProfileChannels() {
Expand Down Expand Up @@ -183,17 +206,6 @@ export default defineComponent({
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
},

maybeLoadVideosForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
await this.loadVideosForSubscriptionsFromRemote()
} else {
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelShortsLocal: async function (channel, failedAttempts = 0) {
const playlistId = getChannelPlaylistId(channel.id, 'shorts', 'newest')
const feedUrl = `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,23 @@ export default defineComponent({
},
},
mounted: async function () {
this.loadVideosFromCacheSometimes()
this.loadVideosFromRemoteFirstPerWindowSometimes()
},
methods: {
loadVideosFromRemoteFirstPerWindowSometimes() {
if (!this.fetchSubscriptionsAutomatically) {
this.loadVideosFromCacheSometimes()
return
}
if (this.$store.getters.getSubscriptionForVideosFirstAutoFetchRun) {
// Only auto fetch once per window
this.loadVideosFromCacheSometimes()
return
}

this.loadVideosForSubscriptionsFromRemote()
this.$store.commit('setSubscriptionForVideosFirstAutoFetchRun')
},
loadVideosFromCacheSometimes() {
// Can only load reliably when cache ready
if (!this.subscriptionCacheReady) { return }
Expand All @@ -128,7 +142,16 @@ export default defineComponent({
return
}

this.maybeLoadVideosForSubscriptionsFromRemote()
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
this.loadVideosForSubscriptionsFromRemote()
return
}

// Auto fetch disabled, not enough cache for profile = show nothing
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
},

async loadVideosFromCacheForAllActiveProfileChannels() {
Expand Down Expand Up @@ -211,17 +234,6 @@ export default defineComponent({
this.batchUpdateSubscriptionDetails(subscriptionUpdates)
},

maybeLoadVideosForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
await this.loadVideosForSubscriptionsFromRemote()
} else {
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelVideosLocalScraper: async function (channel, failedAttempts = 0) {
try {
const result = await getLocalChannelVideos(channel.id)
Expand Down
34 changes: 33 additions & 1 deletion src/renderer/store/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const state = {
lastCommunityRefreshTimestampByProfile: {},
lastPopularRefreshTimestamp: '',
lastTrendingRefreshTimestamp: '',
subscriptionFirstAutoFetchRunData: {
videos: false,
liveStreams: false,
shorts: false,
communityPosts: false,
},
}

const getters = {
Expand Down Expand Up @@ -164,6 +170,19 @@ const getters = {
getLastPopularRefreshTimestamp(state) {
return state.lastPopularRefreshTimestamp
},

getSubscriptionForVideosFirstAutoFetchRun(state) {
return state.subscriptionFirstAutoFetchRunData.videos === true
},
getSubscriptionForLiveStreamsFirstAutoFetchRun (state) {
return state.subscriptionFirstAutoFetchRunData.liveStreams === true
},
getSubscriptionForShortsFirstAutoFetchRun (state) {
return state.subscriptionFirstAutoFetchRunData.shorts === true
},
getSubscriptionForCommunityPostsFirstAutoFetchRun (state) {
return state.subscriptionFirstAutoFetchRunData.communityPosts === true
},
}

const actions = {
Expand Down Expand Up @@ -944,7 +963,20 @@ const mutations = {

setExternalPlayerCmdArguments (state, value) {
state.externalPlayerCmdArguments = value
}
},

setSubscriptionForVideosFirstAutoFetchRun (state) {
state.subscriptionFirstAutoFetchRunData.videos = true
},
setSubscriptionForLiveStreamsFirstAutoFetchRun (state) {
state.subscriptionFirstAutoFetchRunData.liveStreams = true
},
setSubscriptionForShortsFirstAutoFetchRun (state) {
state.subscriptionFirstAutoFetchRunData.shorts = true
},
setSubscriptionForCommunityPostsFirstAutoFetchRun (state) {
state.subscriptionFirstAutoFetchRunData.communityPosts = true
},
}

export default {
Expand Down

0 comments on commit 30f95e5

Please sign in to comment.