mirror of
https://github.com/block/buzz.git
synced 2026-11-24 02:02:07 +00:00
[#9444](https://github.com/block/buzz/pull/9444) narrows the live presence subscription (kind 20001) to the people the app has shown this session. That set only grows, so scrolling through a long DM list or opening many profiles keeps receiving presence for people who are no longer on screen, and each new person reopens the subscription with everyone seen so far. This was raised in [Jude's review](https://github.com/block/buzz/pull/9444#pullrequestreview-5896221680). With this change, presence follows only who is on screen now: - `track` returns a release callback. DM rows and profile sheets release when they unmount. Counts are per person, so someone shown in a DM row and an open profile sheet stays followed until both are gone. - A person nobody has shown for at least 30 seconds is retired: dropped from the tracked set and the cache, and the live subscription is replaced with one for the people still shown. A sweep every 30 seconds retires everyone whose own 30 seconds are up, so each person stays followed for 30 to 60 seconds after their release and the subscription narrows at most once per 30 seconds. Scrolling back within 30 seconds keeps the current subscription. - A read that started before someone was retired doesn't fill in their presence if they are shown again; they wait for a read of their own. - When nobody is shown, the stream closes, and the next person shown opens a new one immediately. - Switching communities keeps following people still on screen, instead of dropping everyone. ### Regressions - **Mention picker ranking.** The picker reads the presence cache without tracking anyone itself, so it ranks by presence only for people currently on screen (before, also for anyone shown earlier in the session). Keeping a retired person's last value would show stale presence, which is worse. - **Dot pop-in.** A retired person's dot is missing when they come back (scrolling back after 30 seconds, or switching the Home filter to Solo and back after 30 seconds) until the replacement subscription is ready and their snapshot read returns. On a slow link that can take seconds. Before, the dot stayed for the whole session. - **Network.** A retirement costs one replacement REQ and a CLOSE, at most once per 30 seconds of scrolling. A person shown again after being retired costs one snapshot read, the same as the first time they were shown. - **Reliability.** Narrowing uses #9444's replacement path (the old stream stays until the new one is ready), so a failed narrowing keeps the wider stream and the poll retries it. ### Validation iPhone 12 mini on Builderlab (measured on [bda9e214f](https://github.com/block/buzz/commit/bda9e214f), before the sweep change), cold launch, scroll the Home list to the bottom and back to the top, then 60 s idle: | | #9444 head | This PR | | --- | --- | --- | | Live presence authors at the end | 37 (only grows) | 1 (37 at the bottom, then 11, then 1) | | Presence events while idle (60 s) | 29 (10.7 KB) | 0 | | Presence REQs during the run | 36 | 37 | Presence dots still show on the DM rows visible at the bottom of the list. Both heads still reopen the subscription once per newly shown person while scrolling (36 swaps for 37 people); batching those during a fling would be the next bound, and is not part of this PR. Added tests: - A person shown in two places stays followed until both release. Released people leave the subscription only after the delay, and their late live events are ignored. - Showing someone again within the delay keeps the same subscription and their cached presence. - Releasing everyone closes the stream, and the next person shown gets a new subscription and a snapshot read right away. - Scrolling 500 rows past a window of 10 leaves a subscription for exactly the last 10, with exactly two replacement opens after scrolling stops (the sweeps 30 s apart). - A person released 29 seconds after another keeps their subscription and cached presence when the first one is retired, and is retired at a later sweep. - A person retired while their snapshot is in flight stays absent. - A read started a second before someone is retired doesn't fill them in once they're shown again; the other people in that read keep their results, and the person's own read does. - Production seam: removing a DM row from the Home list stops following that person after the delay (the stream closes and the cache empties). Each guard was mutation-checked: removing it fails at least one of these tests. Changed test: the community-switch snapshot test now expects people still on screen to be read in the new community. Full mobile suite: 4857 passed, 71 skipped (onca0066de3, after rebasing onto main). --------- Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>