Fix Sentry 1G8P/1FWW/1GSX/1G4S/1GC3/1GB9: track Reader posts off main thread#22862
Draft
nbradbury wants to merge 1 commit into
Draft
Fix Sentry 1G8P/1FWW/1GSX/1G4S/1GC3/1GB9: track Reader posts off main thread#22862nbradbury wants to merge 1 commit into
nbradbury wants to merge 1 commit into
Conversation
…r posts off main trackPostAtPositionIfNeeded ran ReaderPostTable.getBlogPost (rawQuery) twice on the main thread from a Handler.postDelayed in the pager. With a busy SQLite connection pool this exceeded the ANR budget. Wrap trackPost in lifecycleScope.launch(Dispatchers.IO) so the DB reads, the Volley page-view ping, and the analytics call all run off-main. The existing collaborators are already thread-safe: - bumpPageViewForPost queues a Volley request. - markPostAsSeenSilently launches its own coroutine. - readerTracker.trackPost only forwards to AnalyticsTracker. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Generated by 🚫 Danger |
Contributor
|
|
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Fixes a cluster of Reader pager ANRs where
ReaderPostPagerActivity.trackPostAtPositionIfNeededperformed twoReaderPostTable.getBlogPost(rawQuery) calls synchronously on the main thread from aHandler.postDelayed:When the SQLite connection pool was busy (Reader sync) the rawQuery parked on
acquireConnectionlong enough to trip the 5s ANR threshold.Changes
ReaderPostPagerActivity.trackPostnow runs insidelifecycleScope.launch(Dispatchers.IO). The collaborators it calls are all thread-safe:ReaderPostActions.bumpPageViewForPost— queues a Volley request.ReaderPostSeenStatusWrapper.markPostAsSeenSilently— already launches its own coroutine onBG_THREAD.ReaderTracker.trackPost— forwards toAnalyticsTracker.No UI code runs in the moved block, so dispatching to IO is safe.
Test plan
READER_ARTICLE_OPENEDanalytics still fire for each newly viewed post (check Tracks/console).lifecycleScopeshould cancel pending work cleanly without a leak.🤖 Generated with Claude Code