-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Post List: Fix excessive media requests #20939
Conversation
Generated by 🚫 Danger |
Quality Gate passedIssues Measures |
📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #20939 +/- ##
==========================================
+ Coverage 40.93% 40.95% +0.01%
==========================================
Files 1518 1518
Lines 69550 69558 +8
Branches 11473 11474 +1
==========================================
+ Hits 28473 28488 +15
+ Misses 38491 38486 -5
+ Partials 2586 2584 -2 ☔ View full report in Codecov by Sentry. |
featuredImageIds.forEach { | ||
featuredImageMap.remove(it) | ||
ongoingRequests.remove(it) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be called when the featured image request is completed? I mention this because I haven't found any other place where the ongoing request is removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the question, which @AjeshRPai answered before me down below #20939 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The places where this funcation gets called is PostListEventListener → featuredMediaChanged.
The featuredMediaChanged is called when the media is changed or uploaded. Correct me if I am wrong.
This is correct, previously only success calls were removed from the featureImageMap and in the updated version, both success and errors are removed. We need to make sure we don't have requests hanging around when they shouldn't be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the testing instructions and confirmed that only one request is made per featured image. Thanks @zwarm for addressing this issue 🙇 !
I've checked the code and looks good to me, however, I'd defer the approval to an Android developer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes looks good to me. Feel free to merge 👍🏼
featuredImageIds.forEach { | ||
featuredImageMap.remove(it) | ||
ongoingRequests.remove(it) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #20905
This PR fixes the excessive calls to fetch media when loading the post list by introducing and managing ongoing fetch requests in
PostListFeaturedImageTracker
. These changes aim to prevent redundant fetch requests.Changes include
PostListFeaturedImageTracker
IntroducedongoingRequests
, to keep track of ongoing image fetch requests and prevent redundant requests.getFeaturedImageUrl()
to check and update theongoingRequests
set appropriately.PostListEventListener.onMediaChanged()
to invokeinvalidateFeaturedMedia
on both success and error. This ensures that thefeaturedImageMap
andongoingRequests
are properly updated whether the media fetch was successful or not.To Test:
Steps to reproduce the behavior
Preparation:
Existing: Extra requests to the media endpoint for the same featuredImageId
Fix: Extra requests to the media endpoint are eliminated
Alternative to using Charles
GSONRequest.parseNetworkRequest
to log infoRegression Notes
Potential unintended areas of impact
Multiple media requests continue to be excessive
What I did to test those areas of impact (or what existing automated tests I relied on)
Manual and unit testing
What automated tests I added (or what prevented me from doing so)
Existing tests
PR Submission Checklist:
RELEASE-NOTES.txt
if necessary.Testing Checklist (strike-out the not-applying and unnecessary ones): N/A