Reduce redundant DB writes for users and channel configs#6509
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
SDK Size Comparison 📏
|
WalkthroughTwo repository ChangesRepository insert deduplication
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
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
`@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/UserRepositoryTests.kt`:
- Around line 146-147: The test assertion on line 146 in UserRepositoryTests.kt
is over-constraining by verifying a specific insertion order using
shouldBeEqualTo with listOf(id, other.id), but the actual contract only requires
dedup-by-id and last-wins semantics. Replace the order-dependent assertion with
one that verifies both user entities are present regardless of order (such as
checking that the map contains both ids without asserting list equality), while
keeping the existing assertion on line 147 that validates the entity with the
matching id has the correct "last" name value.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2185fa27-889e-4a18-94a0-33dc4c8fbf3e
📒 Files selected for processing (4)
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/internal/offline/repository/domain/channelconfig/internal/DatabaseChannelConfigRepository.ktstream-chat-android-client/src/main/java/io/getstream/chat/android/client/internal/offline/repository/domain/user/internal/DatabaseUserRepository.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/ChannelConfigRepositoryTest.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/UserRepositoryTests.kt
d8419f8 to
24c6e42
Compare
|



Goal
Persisting a channel response fans out into redundant SQLite writes: the same user gets inserted once per reference in the payload, and the channel list rewrites each channel's config once per channel. A customer flagged the volume. This dedups before the DB write, with no behaviour change.
Closes AND-1247
Implementation
insertUsers: dedup users by id (Channel.users()lists the same user once per member/author/watcher/etc.).insertChannelConfigs: dedup configs by type (one row per type, not per channel).Both keep the last occurrence, matching the existing
INSERT OR REPLACEbehaviour.Testing
UserRepositoryTestsandChannelConfigRepositoryTestcovering the dedup.Summary by CodeRabbit
Bug Fixes
Tests