perf(persistence): Move pinned messages pagination to SQL#2689
perf(persistence): Move pinned messages pagination to SQL#2689VelikovPetar wants to merge 25 commits into
Conversation
# Conflicts: # packages/stream_chat_persistence/CHANGELOG.md
…ture/FLU-485_optimize_read_message_from_db_part2 # Conflicts: # packages/stream_chat_persistence/CHANGELOG.md # packages/stream_chat_persistence/lib/src/dao/message_dao.dart
…b' into feature/FLU-485_optimize_read_message_from_db_part2
📝 WalkthroughWalkthroughThis PR refactors pinned message pagination in ChangesPinned Message Cursor Pagination
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
…e_pinned_message_pagination_to_sql # Conflicts: # packages/stream_chat_persistence/CHANGELOG.md # packages/stream_chat_persistence/lib/src/dao/message_dao.dart # packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart # packages/stream_chat_persistence/test/src/dao/message_dao_test.dart # packages/stream_chat_persistence/test/src/dao/pinned_message_dao_test.dart
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart`:
- Around line 246-255: The cursor lookup currently calls
_lookupCursor(messagePagination?.lessThan/lessThanOrEqual/greaterThan/greaterThanOrEqual)
which resolves by id only and can match cursors from other channels; update
_lookupCursor to accept a cid/channelCid parameter (e.g., _lookupCursor(cid,
cursorId)) and change the calls inside getMessagesByCid to pass the active
channel's cid so lookups are scoped to that channel; also update the other
occurrence (the block around the second set of calls) to pass cid when invoking
_lookupCursor and adjust the helper implementation to filter by channelCid when
resolving cursor ids.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4373489d-563d-4324-afce-ee6ada4ddc00
📒 Files selected for processing (3)
packages/stream_chat_persistence/CHANGELOG.mdpackages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dartpackages/stream_chat_persistence/test/src/dao/pinned_message_dao_test.dart
| final ( | ||
| lessThanCursor, | ||
| lessThanOrEqualCursor, | ||
| greaterThanCursor, | ||
| greaterThanOrEqualCursor, | ||
| ) = await ( | ||
| _lookupCursor(messagePagination?.lessThan), | ||
| _lookupCursor(messagePagination?.lessThanOrEqual), | ||
| _lookupCursor(messagePagination?.greaterThan), | ||
| _lookupCursor(messagePagination?.greaterThanOrEqual), |
There was a problem hiding this comment.
Scope cursor lookup to the active channel.
_lookupCursor resolves by id only. If a cursor id exists in another channel, it can still produce a cutoff and incorrectly filter this channel instead of behaving like a no-op. Please scope lookup by channelCid and pass cid from getMessagesByCid.
Suggested fix
- ) = await (
- _lookupCursor(messagePagination?.lessThan),
- _lookupCursor(messagePagination?.lessThanOrEqual),
- _lookupCursor(messagePagination?.greaterThan),
- _lookupCursor(messagePagination?.greaterThanOrEqual),
+ ) = await (
+ _lookupCursor(cid, messagePagination?.lessThan),
+ _lookupCursor(cid, messagePagination?.lessThanOrEqual),
+ _lookupCursor(cid, messagePagination?.greaterThan),
+ _lookupCursor(cid, messagePagination?.greaterThanOrEqual),
).wait;
...
- Future<({DateTime createdAt, String id})?> _lookupCursor(String? id) async {
+ Future<({DateTime createdAt, String id})?> _lookupCursor(
+ String cid,
+ String? id,
+ ) async {
if (id == null) return null;
final createdAt = await (selectOnly(pinnedMessages)
..addColumns([pinnedMessages.createdAt])
..where(pinnedMessages.id.equals(id))
+ ..where(pinnedMessages.channelCid.equals(cid))
..where(
pinnedMessages.parentId.isNull() |
pinnedMessages.showInChannel.equals(true),
))
.map((row) => row.read(pinnedMessages.createdAt))
.getSingleOrNull();Also applies to: 358-366
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart` around
lines 246 - 255, The cursor lookup currently calls
_lookupCursor(messagePagination?.lessThan/lessThanOrEqual/greaterThan/greaterThanOrEqual)
which resolves by id only and can match cursors from other channels; update
_lookupCursor to accept a cid/channelCid parameter (e.g., _lookupCursor(cid,
cursorId)) and change the calls inside getMessagesByCid to pass the active
channel's cid so lookups are scoped to that channel; also update the other
occurrence (the block around the second set of calls) to pass cid when invoking
_lookupCursor and adjust the helper implementation to filter by channelCid when
resolving cursor ids.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2689 +/- ##
==========================================
+ Coverage 65.96% 65.99% +0.03%
==========================================
Files 425 425
Lines 26926 26950 +24
==========================================
+ Hits 17761 17785 +24
Misses 9165 9165 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Submit a pull request
Linear: FLU-487
Review after: #2679
CLA
Description of the pull request
limitalways being applied from the beginning of the fetched messagesgreaterThanOrEqual/lessThanOrEqualpaginationSummary by CodeRabbit
New Features
Bug Fixes