Files
buzz/mobile/test/features/channels/channels_page_test
Tom Brow 61c070d591 perf(mobile): derive Active filter activity from the channel list, with no per-channel relay reads (#9832)
The Active section filter needs to know when each channel last had a
message. Since #8479 (saved channel section filters) and #9796 (section
filter refinements), the app has looked that up with its own relay
history read per channel in every section that uses the filter. Since
#9885, main caches what the channel list's read and live delivery saw
for each channel (its latest post, or that it has none), and looks a
channel up only while the list has no cached evidence for that channel.
The lookup's own answer is not cached, so it runs again on every resume
while that lasts. A failed lookup shows the notice with Retry at once
and is also retried automatically up to three times. Channels the list's
batched read misses (for example when it fails or hits its deadline) and
every channel after a channel list rebuild, which clears the cache, all
go through that lookup. With many channels, those reads compete with the
channel list's own reads and the read-state sync for the relay's request
budget. When they time out or get rate limited, the app shows an
"activity couldn't load" notice, and the same pressure can delay other
requests such as read-state sync.

The channel list already reads each channel's latest messages in one
batched request when it loads. This change records the newest message
time from that read (self-authored and muted messages included, unlike
`lastMessageAt`) and keeps it current from live delivery and from the
unread catch-up the list already sends after a reconnect. Where that
catch-up starts after posts no read has covered yet (for example, a post
that arrived while offline and was read on another device), a separate
small request sent after the catch-up asks for the newest one with a
single `limit: 1` filter per such channel. It is sent only for channels
an Active section is showing, only when the gap could hold a newer post
than the one already known (including one the catch-up itself just
verified), and without the per-channel websocket fallback, so a failure
there leaves only that channel's activity unknown and never delays
unread state. A successful refresh replaces a channel's time, so a
deleted latest post stops counting, while keeping any newer message that
arrived during the read. Only messages whose signature verifies count,
and the app verifies only a message that would change a channel's
activity. When a channel's latest post is deleted, live or while
offline, the app forgets that channel's activity, so it reads as unknown
(and stays visible) until the next background list read re-reads it on
resume, reconnect or a list change, if an Active section shows it. A
channel the last list read missed is asked for again the same way. The
Active filter reads that value, so it sends no relay requests of its
own. This replaces main's cache together with its fallback lookup, the
lookup's retries and Retry. Because the filter can no longer fail on a
lookup, the "activity couldn't load" notice is removed too.

### Validation

- **Network impact.** Before: one history read for each channel in an
Active-filtered section while the list has no cached evidence for that
channel, again on each resume while that lasts, with up to three
automatic retries plus a manual Retry when it fails. After: no reads of
its own. The filter reuses the list's existing batched read. Only for
channels an Active section shows, the next background list read asks
again for a channel whose latest post was deleted or failed
verification, and a reconnect may send the gap read below.
- Provider tests check that activity comes from the list read, live
delivery and a reconnect's catch-up; ignores a message with a bad
signature; includes self-authored messages; counts a future-dated post
as now; leaves `lastMessageAt` untouched and sends no extra requests;
stays unknown (the channel stays visible) when a read or catch-up fails;
survives a same-community rebuild; picks up a post read on another
device while offline, including after an offline rebuild resets the
unread cursor; drops a deleted latest post on refresh, and forgets it
until the next list read on a live deletion or a deletion the catch-up
returns; skips the gap read for a channel no Active section shows, or
one whose catch-up found a newer verified post; asks again for a channel
whose list read had no verifiable post; and keeps a live post that
arrives during a refresh.
- Simulator run on a signed-in community: set a section to Active (7
days), then backgrounded and resumed the app and pulled to refresh.
Inactive channels stayed collapsed under Show more, and no notice
appeared.

### Regressions

- Signature checks for read and catch-up results run in a background
isolate and check only each channel's newest message, so only those
messages are copied off the UI isolate. A channel whose newest message
fails verification is not updated by that read (unknown after a catch-up
or gap read, so it stays visible) instead of falling back to an older
one. Unread state from a catch-up is published first; its activity lands
once those checks finish. A live message is checked on the UI isolate,
and only when it is newer than the known activity.
- Channels the batch doesn't cover (for example non-member or archived
channels, or a batch that hits its deadline) have unknown activity. The
filter fails open for them, so they stay visible, which matches how it
treated a failed lookup before.
- A catch-up that finds only newer self-authored, muted or already-read
messages now republishes the list once, so the filter sees them. Before,
it published nothing.
- After a reconnect, channels an Active section shows, whose catch-up
would skip posts no read has covered, get one `limit: 1` filter each in
one small extra request, sent after the unread catch-up. It adds at most
one event per such channel, against main's per-channel lookup (with its
retries) for every Active channel the list has no cached evidence for. A
rate-limit refusal of either request still pauses the session's reads,
since the relay's quota covers every request this client makes.
- A channel with a gap to read reads as unknown, so it stays visible,
until that read answers.
- A channel no Active section shows, whose catch-up would skip uncovered
posts, reads as unknown until a later catch-up runs while it is shown.
- A channel whose catch-up or gap read fails (including a catch-up that
fails before sending) reads as unknown, so it shows unfiltered until a
later read succeeds. A failed gap read is not retried by itself; the
next list read's catch-up asks again, so it adds no retry traffic.
- A post dated ahead of the device clock (the relay accepts up to 15
minutes) counts as activity now.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
2026-11-24 16:33:09 -08:00
..