Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reader][0 blogs/0 tags] Fix Subscription feed infinite loading and fetch when tapping filters #20216

Merged

Conversation

thomashorta
Copy link
Contributor

Fixes #20009
Fixes #20010

The biggest change in this PR is fixing the logic inside ReaderUpdateLogic to avoid unnecessary DB writes which were happening always, even when the server tag list was the same as the local tag list, which in turn made the FollowTagsChanged stop being triggered every single time a fetch was done.

Fixing that issue made the FollowTagsChanged event only be triggered when we, in fact, had changes in the local tag DB, which solved the issues referenced above BUT broke a lot of other things, since much of the existing code listening to that event was relying on FollowTagsChanged being triggered at the end of all tag fetching tasks.

To solve that I renamed the FollowTagsChanged to FollowTagsFetched and made it trigger in the same situation as it was before (regardless of changes being made to the local DB), added a new field didChange to propagate the information if a change was done locally or not, and updated the logic in ReaderPostListFragment event listener that caused the 2 bugs above to happen, by guarding with the specific conditions in which we really want fetching to happen


To Test:

Before running each test scenarios below make sure you have 0 blogs and 0 tags followed.

Infinite loading after subscribing to tags

  1. Install and log into Jetpack on a feature/reader-ia branch build
  2. Go to reader
  3. Go to the Subscriptions feed
  4. Tap "0 tags" filter pill
  5. Tap "Suggested tags"
  6. Choose zero or more tags and tap "Done"/back
  7. Verify it goes back to Subscription Feed and the page has no infinite loading indicator

Tapping the blog/tag filter pills causes the empty list to refresh

  1. Install and log into Jetpack on a feature/reader-ia branch build
  2. Go to reader
  3. Go to the Subscriptions feed
  4. Tap either the "0 blogs" or "0 tags" filter pill
  5. Verify the feed does not try to refresh since there are no subscribed blogs

Regression Notes

  1. Potential unintended areas of impact

    • Normal scenarios of reader (with tags/blogs subscriptions)
  2. What I did to test those areas of impact (or what existing automated tests I relied on)

    • Manual testing
  3. What automated tests I added (or what prevented me from doing so)

    • Updated existing unit tests

PR Submission Checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing Checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

Thomas Horta added 6 commits February 20, 2024 14:34
IMPORTANT: this breaks ReaderPostListFragment/ViewModel fetch logic because it
was relying on this bug causing FollowedTagsChanged to be triggered in the
EventBus all the time. With this fix the Subscriptions feed is completely broken
(and the other feeds that use this Fragments are likely to be broken as well,
which are all the other except Discover).
The empty view is being reused for showing several messages, including the fetch
message. Because of that, that are pieces of code that rely on previous code
showing the "empty view" and just alter its content, without calling "show"
again. If we hide the empty view when the list is actually empty, we get to
a scenario of a blank screen when coming back to this feed from some other
screens. Example: with 0 blog subscriptions, in the Subscriptions feed, going to
the tag suggestions and back cause the Subscriptions feed to be blank.
Tag Interests has an infinite loading because a use case expects the event that
is not triggered anymore (I think).
Upon investigation I realized that most places using this event were actually
using it as a callback for the end of the fetch task rather than something that
is ONLY emitted when the tags CHANGE, which was what the name implied.

That only worked because of the bug mentioned in commit 3017bab that did not
properly compare the local and server tags and considered all fetches as
requiring a local database write, which in turn triggered the event.

The constant triggering of that FollowedTagsChanged event was also the cause of
bugs #20009 and #20010 since part of the code that runs there was actually only
supposed to run some times.

To fix that I renamed it to FollowedTagsFetched to better represent what it does
and figured out which parts of the code inside `ReaderPostListFragment` event
listener were supposed to run and in which scenario. I also added a `didChange`
field in the `FollowedTagsFetched` event for completeness but that part might
not be needed in the future, since the only code using that is legacy code
related to the old subfilter which should be removed in the future.
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 20, 2024

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr20216-c702921
Commitc702921
Direct Downloadjetpack-prototype-build-pr20216-c702921.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 20, 2024

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr20216-c702921
Commitc702921
Direct Downloadwordpress-prototype-build-pr20216-c702921.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (40ece18) 40.31% compared to head (c702921) 40.31%.
Report is 9 commits behind head on trunk.

Files Patch % Lines
...d/ui/reader/services/update/ReaderUpdateLogic.java 0.00% 7 Missing ⚠️
...ss/android/ui/reader/actions/ReaderTagActions.java 0.00% 5 Missing ⚠️
.../org/wordpress/android/ui/reader/ReaderEvents.java 33.33% 4 Missing ⚠️
...va/org/wordpress/android/models/ReaderTagList.java 0.00% 2 Missing ⚠️
...org/wordpress/android/datasets/ReaderTagTable.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #20216      +/-   ##
==========================================
- Coverage   40.31%   40.31%   -0.01%     
==========================================
  Files        1469     1469              
  Lines       67672    67676       +4     
  Branches    11211    11209       -2     
==========================================
+ Hits        27281    27282       +1     
- Misses      37897    37900       +3     
  Partials     2494     2494              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@RenanLukas RenanLukas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @thomashorta . It's working as expected.
I'm approving since code LGTM but left a suggestion.

@@ -26,16 +26,27 @@ private ReaderEvents() {
throw new AssertionError();
}

public static class FollowedTagsChanged {
public static class FollowedTagsFetched {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

|| displayNameUpdateWasNeeded
) {
boolean didChangeFollowedTags = false;
if (!localTopics.isSameList(serverTopics)) {
AppLog.d(AppLog.T.READER, "reader service > followed topics changed "
+ "updatedDisplayNames [" + displayNameUpdateWasNeeded + "]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the variable displayNameUpdateWasNeeded was removed from the if and is now only used in this AppLog, would it make sense to remove it? If so, perhaps we can even remove the displayNameUpdateWasNeeded method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I thought I had removed it but I think I forgot! Thanks for noticing that!

Copy link
Contributor

@daniloercoli daniloercoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. However, I noticed that we're retrieving the tags list and triggering the FollowTagsChanged event too many times, even when it seems unnecessary. The event is fired when tapping on the Tags pills to open the bottom sheet and also when tapping on the edit button in the bottom sheet. I'm wondering if we really need to sync tags with this frequency.

@thomashorta
Copy link
Contributor Author

Looks good to me. However, I noticed that we're retrieving the tags list and triggering the FollowTagsChanged event too many times, even when it seems unnecessary. The event is fired when tapping on the Tags pills to open the bottom sheet and also when tapping on the edit button in the bottom sheet. I'm wondering if we really need to sync tags with this frequency.

Do you mean the logic to fetch the tags, which ends up triggering now the FollowTagsFetched? If that's the case I kind of agree but as said in the PR comments and some of the commit messages unfortunately there are a lot of places currently starting the "fetching" tasks and waiting for that "fetch ended" event, so a proper rearchitecture would be great to check if we indeed need all that fetching.

For the examples you mentioned ("tapping the tag pills" and "edit button") I think those are actually very good examples that makes sense to keep fetching and syncing the tags, since they are the main entry points for screens that display the subscribed tags to the user, so in my opinion those scenarios need to keep fetching data from the backend.

But like any other app/feature that has caching, the "fetch policy" is hard to get right and there's always a trade-off. Ex: using "cache-first" will return fast but might show stale data, while "network-only" might be slow but will guarantee we're synced with the backend.

@daniloercoli
Copy link
Contributor

daniloercoli commented Feb 21, 2024

For the examples you mentioned ("tapping the tag pills" and "edit button") I think those are actually very good examples that makes sense to keep fetching and syncing the tags, since they are the main entry points for screens that display the subscribed tags to the user, so in my opinion those scenarios need to keep fetching data from the backend.

I don't completely agree with the part above. It's ok to fetch from the server when tapping Edit, since the intent is to modify the list. If you regularly use the Reader, and switch between tags during a single session, there's no need to sync every time you tap to open the bottom sheet. In my case, and i think on most regular users, a single sync at app startup is more than sufficient, as I don't add/remove tags daily but instead often check the content of my preferred tags.

@thomashorta
Copy link
Contributor Author

Regarding CodeCov message above (#20216 (comment)), I don't think there's any action to be done, since none of those files were covered by unit tests, and adding those tests in this fix is out of scope.

@thomashorta
Copy link
Contributor Author

If you regularly use the Reader, and switch between tags during a single session, there's no need to sync every time you tap to open the bottom sheet. In my case, and I think on most regular users, a single sync at app startup is more than sufficient, as I don't add/remove tags daily but instead often check the content of my preferred tags.

That's a good point! There's definitely room for improvement there in terms of fetching that should be investigated when we decide to refactor the business logic and architecture behind the Reader.

@thomashorta thomashorta merged commit a3b6de7 into trunk Feb 21, 2024
19 checks passed
@thomashorta thomashorta deleted the issue/20010-reader-ia-subscription-infinite-loading branch February 21, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants