FreeTube icon indicating copy to clipboard operation
FreeTube copied to clipboard

Update subscription cache when visiting a channel

Open absidue opened this issue 2 years ago • 1 comments

Update subscription cache when visiting a channel

Pull Request Type

  • [x] Feature Implementation

Description

Currently when you visit a channel, we fetch the latest information from YouTube and display it to the user, we also update the channel name and thumbnail in the subscriptions database. What we don't do yet is update the subscriptions cache with the videos, shorts, live and community post content that we got.

This pull request changes the channel page, so that it updates the subscription cache with the information on the channel page. For the videos, live and community tabs, we just overwrite the current cache for that channel, as what we just received is the last known state (same as what a refresh on the subscriptions page would do). For the shorts tab we unfortunately cannot do that, as the shorts channel tab doesn't have published dates (we need them for sorting on the subscriptions page), on the subscriptions page we always use RSS for the shorts tab, instead this pull request will just update the title, channel name and view count of the existing items in the cache.

You might be wondering what the point of this is, as we don't syncronise the subscription cache across windows (each window has it's own one https://github.com/FreeTubeApp/FreeTube/issues/4152) and don't persist it on disk, so they disappear between app launches. This is basically a "free" subscription refresh for the visited channel as we already have the information without making any additional API requests. It will mostly benefit users that use the same window for a long time, but will help if we do implement synchronisation across windows in the future or disk persistence, as it would also allow us to reduce API requests (e.g. this channel was refreshed less than 1 minute ago, no need to fetch it again).

Testing

As waiting for any of your subscribed channels to upload a new video would be a slow and unpredictable test case, here are two that allow you to skip the waiting.

Please note that all steps for a given test case have to be performed in the same window, as we don't synchronise the subscription cache between windows yet

Test case 1

This test case will require you to have DeArrow disabled and either not have any watch history or for you to pick a channel that has videos that you haven't watched.

  1. Enable Fetch feeds from RSS in the Subscription Settings section
  2. Refresh your subscriptions
  3. Visit one of the channels that you are subscribed to
  4. Go back to the subscriptions page
  5. Notice that video durations have shown up for the videos on that channel (if you have DeArrow enabled or have watched any of those videos, FreeTube would be showing the duration from there instead of nothing, so you wouldn't notice the difference).

Test case 2

  1. Disable Fetch feed automatically in the Subscription Settings section
  2. Create a new profile
  3. Subscribe to a channel that you aren't subscribed to yet from the search results or watch page (don't visit the channel page yet).
  4. Visit the subscriptions page and notice that it is empty
  5. Visit the channel
  6. Go back to the subscriptions page and notice that the videos, live and community tabs should now be populated (shorts won't be as the shorts channel tab doesn't have published dates, so we can only update the metadata in the existing cache, as we need the published dates for sorting)

Desktop

  • OS: Windows
  • OS Version: 10
  • FreeTube version: 0.19.1

absidue avatar Feb 11 '24 17:02 absidue

If this is merged first, https://github.com/FreeTubeApp/FreeTube/pull/4380 will need to test about this Otherwise this need to test for that PR With current state it's probably the earlier

PikachuEXE avatar Feb 12 '24 01:02 PikachuEXE