Skip to content

perf(llc): make primitive value streams distinct - #2935

Merged
xsahil03x merged 1 commit into
masterfrom
fix/distinct-member-count-stream
Sep 3, 2026
Merged

xsahil03x merged 1 commit into
masterfrom
fix/distinct-member-count-stream

Conversation

@xsahil03x

@xsahil03x xsahil03x commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Channel and ClientState getters that map to a single primitive value emitted on every channel-state / current-user update, even when the value was unchanged. Pushing four distinct message counts through messageCountStream produced 13 emissions; memberCountStream fired on every new message.

Those getters now .distinct(), matching the stream getters in channel.dart that already do (ownCapabilitiesStream, messagesStream, draftStream, …). Scope is primitives only (bool, int, String?, DateTime?) — model and collection streams are untouched.

The composer's distinct() on the draft stream is dropped as redundant; ChannelClientState.draftStream and threadDraftStream already dedupe.

Verification

  • The memberCountStream / messageCountStream tests now push a repeated count through and assert the full emission list. Checked red against origin/master's channel.dart ([null, 1, 5, 10] expected, [null, null, null, 1, 1, 1, 5, 5, 5, 5, 5, 5, 10] actual) and green with this change.
  • stream_chat: dart test 1631 passing, dart analyze --fatal-infos clean.
  • stream_chat_flutter_core: flutter test 362 passing.
  • stream_chat_flutter: flutter test 1311 passing; 2 failures are pre-existing missing macOS goldens for stream_message_deleted_test.dart.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Channel state streams now emit updates only when their values change, reducing duplicate notifications.
    • Unread count streams for channels, threads, and total unread counts now suppress consecutive duplicate values.
    • Draft updates in the message composer are now received for every emission, including repeated values.
  • Documentation
    • Updated changelog documentation to reflect stream emission behavior.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: ea9eb914-8286-43ce-b659-b7c1564cef66

📥 Commits

Reviewing files that changed from the base of the PR and between 0c632c2 and 27bd68b.

📒 Files selected for processing (1)
  • packages/stream_chat/test/src/client/channel_test.dart

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds duplicate suppression to primitive-valued channel and unread-count streams. It updates count tests to verify repeated values emit once. It removes subscription-level deduplication from the message composer draft stream.

Changes

Stream emission behavior

Layer / File(s) Summary
Channel stream deduplication and validation
packages/stream_chat/lib/src/client/channel.dart, packages/stream_chat/test/src/client/channel_test.dart, packages/stream_chat/CHANGELOG.md
Channel status, metadata, count, and watcher streams suppress consecutive duplicate values. Tests verify repeated message and member counts emit once. The changelog records the behavior.
Client unread stream deduplication
packages/stream_chat/lib/src/client/client.dart
Unread channel, thread, and total count streams now return distinct-value streams.
Draft stream subscription
packages/stream_chat_flutter/lib/src/message_input/stream_message_composer.dart
The draft subscription no longer applies .distinct(), so _onDraftUpdate receives every draft emission.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 27bd6

Count streams now suppress repeated values, with tests confirming the intended behavior. No merge-blocking risk remains.

Suggested reviewers: renefloor, velikovpetar

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making primitive-value streams emit distinct values for performance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/distinct-member-count-stream

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Channel and ClientState getters that map to a single primitive value now
dedupe, so listeners only wake up when the value actually changes rather
than on every channel state or current user update.

The composer's redundant `distinct()` on the draft stream is dropped, as
`ChannelClientState.draftStream` and `threadDraftStream` already dedupe.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@xsahil03x
xsahil03x force-pushed the fix/distinct-member-count-stream branch from 0c632c2 to 27bd68b Compare September 3, 2026 13:13
@xsahil03x
xsahil03x enabled auto-merge (squash) September 3, 2026 13:14
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.23%. Comparing base (9610ce2) to head (27bd68b).

Files with missing lines Patch % Lines
packages/stream_chat/lib/src/client/channel.dart 18.75% 13 Missing ⚠️
packages/stream_chat/lib/src/client/client.dart 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2935   +/-   ##
=======================================
  Coverage   74.23%   74.23%           
=======================================
  Files         437      437           
  Lines       28377    28377           
=======================================
  Hits        21066    21066           
  Misses       7311     7311           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants