mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
get_channels populated last_message_at with one limit:1 filter per channel — N top-1 DB queries per sidebar refresh, re-run every 60s (bounded-concurrent since #1457, but still O(N) queries). Replace the N filters with a single bridge extension filter, `latest_per_channel: true` (same raw-JSON pattern as before_id / depth_limit / feed_types): - buzz-db: get_latest_event_per_channel — unnest + LATERAL top-1 per channel riding idx_events_community_channel_created. Unlike DISTINCT ON, the LATERAL LIMIT 1 cannot degrade to a sort; EXPLAIN confirms ordered index scans on every partition. Per-channel ordering (created_at DESC, id ASC LIMIT 1) is byte-identical to query_events with limit:1, so the winning event per channel is unchanged. - bridge /query: new phase ahead of the catch-all. Requested #h channels intersect accessible_channels (same outcome as the catch-all access-scope skip); every returned event passes the identical four per-event gates (filters_match, reader_authorized_for_event, is_author_only_event, event_in_accessible_channel). Top-1-per-channel is guaranteed by construction, so the multi-#h limit-budget hazard that rules out plain multi-#h pushdown does not apply. - desktop get_channels: N filters -> 1 filter. Verified: Postgres-backed equivalence test (bulk winners == serial per-channel winners, incl. same-second id-ASC tie-break, soft-delete and wrong-kind exclusion, kinds None/empty semantics); cargo test -p buzz-relay -p buzz-db green; desktop tauri tests 864 pass; workspace clippy --all-targets -D warnings clean. Co-authored-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: Tyler Longwell <tlongwell@block.xyz>