perf(persistence): Speed up hydrating a page of cached messages#2820
perf(persistence): Speed up hydrating a page of cached messages#2820VelikovPetar wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughCached message and pinned-message hydration now fetches reactions once per batch, derives current-user reactions in memory, and reuses loaded page messages when resolving quoted previews. Out-of-page quotes continue to load with shared locations. ChangesMessage hydration optimization
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2820 +/- ##
=======================================
Coverage 71.28% 71.28%
=======================================
Files 430 430
Lines 26934 26967 +33
=======================================
+ Hits 19199 19223 +24
- Misses 7735 7744 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Submit a pull request
Linear: FLU-
Github Issue: #
CLA
Description of the pull request
Two behavior-preserving optimizations to message-page hydration in
MessageDaoandPinnedMessageDao(the read path behindgetMessagesByCid, thread loads, andgetMessageById). Both cut redundant SQLite work when turning a page of cached rows intoMessageobjects.1. Derive own reactions in memory instead of a second query.
Hydration previously fired two reaction queries per page: one for all reactions (
getReactionsForMessages) and a second for the current user's subset (getReactionsForMessagesByUserId). The current user's reactions are already contained in the first result, so we now filter them in memory (_ownReactionsFrom) and drop the second query entirely.Reaction.userIdmaps directly from thereactions.userIdcolumn, so the in-memory filter is exactly equivalent to the old SQL predicate, and iteration order (createdAt ASC) is preserved.2. Don't re-fetch quoted messages already in the page.
Quoted-message previews were always fetched and re-hydrated via a separate query, even when the quoted message was already one of the rows on the current page.
_resolveQuotedMessagesnow rebuilds in-page quotes from the maps already loaded for the page (reactions, poll, user, location) and only queries the DB for quotes that fall outside the page. In-page reuse is gated onfetchSharedLocation == truebecause a quote must always carry its shared location — when the page didn't load locations, those quotes fall through to the DB branch (which always fetches locations), exactly matching the previous behavior. Quotes remain hydrated a single level deep and never carry a draft.Correctness
getReactionsForMessagesByUserIdis left in place (still public, still directly tested); it's just no longer part of the hydration path.Testing
message_dao/pinned_message_daosuites pass (93 tests), including the quote/reaction/location edge cases (hydrates sharedLocation for quoted message even when fetchSharedLocation=false on the parent,hydrates quotes to a single level only,does not hydrate drafts for quoted messages,hydrates multiple latest and own reactions).dart analyzeis clean on both changed files.Screenshots / Videos
No UI changes.
Summary by CodeRabbit