diff --git a/src/renderer/components/subscriptions-community/subscriptions-community.js b/src/renderer/components/subscriptions-community/subscriptions-community.js index 087023dca3a40..79408b65f89d6 100644 --- a/src/renderer/components/subscriptions-community/subscriptions-community.js +++ b/src/renderer/components/subscriptions-community/subscriptions-community.js @@ -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 } @@ -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() { @@ -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) diff --git a/src/renderer/components/subscriptions-live/subscriptions-live.js b/src/renderer/components/subscriptions-live/subscriptions-live.js index 08c81aad20f57..5153c171a4d0b 100644 --- a/src/renderer/components/subscriptions-live/subscriptions-live.js +++ b/src/renderer/components/subscriptions-live/subscriptions-live.js @@ -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 } @@ -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() { @@ -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) diff --git a/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js b/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js index fadb8dd8c6a02..948e0ccc542d4 100644 --- a/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js +++ b/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js @@ -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 } @@ -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() { @@ -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}` diff --git a/src/renderer/components/subscriptions-videos/subscriptions-videos.js b/src/renderer/components/subscriptions-videos/subscriptions-videos.js index c7ed19f28958f..da6edff2b2aa2 100644 --- a/src/renderer/components/subscriptions-videos/subscriptions-videos.js +++ b/src/renderer/components/subscriptions-videos/subscriptions-videos.js @@ -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 } @@ -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() { @@ -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) diff --git a/src/renderer/store/modules/utils.js b/src/renderer/store/modules/utils.js index 4efb5a0b769d8..19d3e3f6f9004 100644 --- a/src/renderer/store/modules/utils.js +++ b/src/renderer/store/modules/utils.js @@ -58,6 +58,12 @@ const state = { lastCommunityRefreshTimestampByProfile: {}, lastPopularRefreshTimestamp: '', lastTrendingRefreshTimestamp: '', + subscriptionFirstAutoFetchRunData: { + videos: false, + liveStreams: false, + shorts: false, + communityPosts: false, + }, } const getters = { @@ -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 = { @@ -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 {