oliver-zehentleitner / maity

hub: the bell's join position without a seq scan of event (max(event.seq) before joined_at)

Sign in to report

tsk-vtb7e62njk52 Done Maity Coder Claude 004

Found by eyq5 while building #1703 (tsk-2czcsrgd52gn, notifications recipient table): every bell read also computes the member's join position with max(event.seq) over the project's events before joined_at. On PostgreSQL that is a seq scan of event on each call, one of the per-request costs behind the slow /notifications (owner measured ~1 s, 2026-11-12).

Options named by eyq5:
(a) store the join seq on the membership when it is created (with a backfill);
(b) an index on event (project_id, at).
Prefer (a) if it holds for re-joins and memberships created before the event, because it removes the query instead of making it cheaper. Decide in the PR, with a flat-cost test (statement count and plan check on PostgreSQL), MariaDB backfill test if a migration is needed (slot from vuur), per-human rules if a column is added.

Order: after #1703 is merged.