Skip to content

Conversation

@chrisbobbe
Copy link
Collaborator

Instead of just listening to PerAccountStore and (via an ancestor widget) a MessageListView.

Issue #370 is relevant here -- "Maintain total unread counts efficiently". The button causes linear scans through Unreads each time it rebuilds, and ideally we'd avoid that, especially since now it'll rebuild in more cases than it was before. I think the additional cases aren't very many, though: I've thought of just one kind of Zulip event that would cause Unreads but not PerAccountStore and MessageListView to notify listeners, and I added a test exercising that.

Instead of just listening to PerAccountStore and (via an ancestor
widget) a MessageListView.

Issue zulip#370 is relevant here -- "Maintain total unread counts
efficiently". The button causes linear scans through Unreads each
time it rebuilds, and ideally we'd avoid that, especially since now
it'll rebuild in more cases than it was before. I think the
additional cases aren't very many, though: I've thought of just one
kind of Zulip event that would cause Unreads but not PerAccountStore
and MessageListView to notify listeners, and I added a test
exercising that.
@chrisbobbe chrisbobbe added the maintainer review PR ready for review by Zulip maintainers label Dec 6, 2025
Copy link
Member

@rajveermalviya rajveermalviya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisbobbe! LGTM, moving over to Greg's review.

@rajveermalviya rajveermalviya added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Dec 8, 2025
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Small comments below.

The new test exercises a scenario where the old code didn't behave right, so that's good to fix. But there was something else that prompted taking a look at this logic, right? ISTR a conversation a couple of weeks ago (before my vacation) where we were looking at notifyListeners calls in the context of a different change you were making. Remind me what the context was there?

Comment on lines +1026 to +1029
// omit `message`; if present, MessageListView would notify listeners
messages: List.generate(300, (i) =>
eg.streamMessage(id: 950 + i, sender: eg.selfUser,
flags: [MessageFlag.read, MessageFlag.mentioned])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. IIUC, the point is that the message had been in the narrow, and an event removes it from the narrow; but it hadn't been one of the messages fetched, because it was too old. Is that right? I think that high-level strategy would be good to make explicit in the test's main comment above.

It looks like the same thing would happen with a channel or topic narrow if the message got moved out of the channel/topic, too.

// but not PerAccountStore and MessageListView to notify listeners,
// and check that the button responds.

final message = eg.streamMessage(flags: [MessageFlag.mentioned]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the premise of this test scenario is that this message is older than all the messages that get fetched, it'd be good to give it a smaller message ID too in order to be consistent with that.

That or leave all the message IDs out ­— they're really only needed when the messages get constructed in the test out of order from when they were supposed to be sent.

@chrisbobbe
Copy link
Collaborator Author

The new test exercises a scenario where the old code didn't behave right, so that's good to fix. But there was something else that prompted taking a look at this logic, right? ISTR a conversation a couple of weeks ago (before my vacation) where we were looking at notifyListeners calls in the context of a different change you were making. Remind me what the context was there?

I wonder if you're thinking about #1997 (comment) ?

The fix in this PR is something I hadn't noticed at the time. IIRC I spotted it (and #2026) when reviewing #2006.

@gnprice
Copy link
Member

gnprice commented Dec 11, 2025

I wonder if you're thinking about #1997 (comment) ?

No, what I recall is looking at a proposed change that added notifyListeners calls on PerAccountStore, for (some cases of?) some of the event types where we currently avoid those and instead notify only more-specific ChangeNotifiers. (Which is useful for the handful of high-frequency event types like MessageEvent and PresenceEvent.)

Anyway 🤷 I guess that was a coincidence. Not too surprising if there were just two unrelated reasons to be looking at this general area of logic in the span of a few weeks.

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

Labels

integration review Added by maintainers when PR may be ready for integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants