fix(persistence): treat thread reply pagination limit of 0 as unset#2803
fix(persistence): treat thread reply pagination limit of 0 as unset#2803VelikovPetar wants to merge 3 commits into
Conversation
`getThreadMessagesByParentId` moved thread reply pagination into SQL, which turned a `limit` of 0 into `LIMIT 0` (zero rows). The pre-SQL implementation treated 0 as "unlimited" and returned every reply, and both the backend `getReplies` endpoint (0 -> default page) and the iOS SDK (`fetchLimit` 0 -> all rows) treat 0 as unset rather than empty. Only apply the SQL `LIMIT` for a positive limit so a limit of 0 keeps returning all matching replies. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesThread pagination
Estimated code review effort: 2 (Simple) | ~10 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 |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/stream_chat_persistence/lib/src/dao/message_dao.dart (1)
377-378: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winSame
limit: 0bug exists ingetMessagesByCid.
getThreadMessagesByParentIdnow guards againstlimit: 0, butgetMessagesByCidat lines 377-378 still appliesquery.limit(messagePagination.limit)unconditionally whenmessagePagination != null. If a caller passesPaginationParams(limit: 0), this generatesLIMIT 0and returns no messages — the exact bug this PR fixes for thread replies.Consider applying the same
limit > 0guard here for consistency, or document why the behavior should differ between the two methods.🔧 Suggested fix for consistency
- if (messagePagination != null) { + if (messagePagination != null && messagePagination.limit > 0) { query.limit(messagePagination.limit); }🤖 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/message_dao.dart` around lines 377 - 378, getMessagesByCid still applies a zero pagination limit and can return no messages. In getMessagesByCid, only call query.limit when messagePagination.limit is greater than zero, matching the guard used by getThreadMessagesByParentId.
🤖 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.
Outside diff comments:
In `@packages/stream_chat_persistence/lib/src/dao/message_dao.dart`:
- Around line 377-378: getMessagesByCid still applies a zero pagination limit
and can return no messages. In getMessagesByCid, only call query.limit when
messagePagination.limit is greater than zero, matching the guard used by
getThreadMessagesByParentId.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a271cfa2-91ce-4050-b962-6d99d332248c
📒 Files selected for processing (3)
packages/stream_chat_persistence/CHANGELOG.mdpackages/stream_chat_persistence/lib/src/dao/message_dao.dartpackages/stream_chat_persistence/test/src/dao/message_dao_test.dart
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2803 +/- ##
=======================================
Coverage 71.08% 71.08%
=======================================
Files 429 429
Lines 26891 26892 +1
=======================================
+ Hits 19116 19117 +1
Misses 7775 7775 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
MessageDao.getThreadMessagesByParentIdrecently moved offline thread-reply pagination into SQL. That change turned aPaginationParams.limitof0into a SQLLIMIT 0(zero rows), whereas the pre-SQL implementation treated0as "unlimited" and returned every reply.Across the stack,
limit: 0means unset, not "empty":getReplies:limit == 0is treated as unset → default page of 100.fetchLimit == 0→ unlimited (all rows).0→ returned all rows.This PR only applies the SQL
LIMITwhen a positive limit is provided, restoring the "0 = unset → return all matching replies" contract.Low-risk in practice —
PaginationParams.limitis non-nullable and defaults to 10, and no in-repo call site passes 0 — so this is a latent-correctness fix.Scope is intentionally threads only.
getMessagesByCidhas the same unguarded pattern but is left untouched here.Originally surfaced while reviewing #2750 (the v9 backport), where the same fix was applied.
Test
Added
limit of 0 is treated as unset and returns all repliesto thegetThreadMessagesByParentIdgroup: seeds 30 replies, queries withPaginationParams(limit: 0), asserts all 30 come back in ASC order. Full group passes locally.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests