Repository navigation
perf(notifications): one pulse poll, indexable inbox gates, one-statement roles (v1.18.0) - #103
Merged
Merged
Conversation
…ment roles (v1.18.0) Cuts the steady-state request and query load without changing what anyone sees (INNOBOX_SPEC.md v0.19: §4.2 Resolution, §5 notifications, §12.1, §12.2 pulse). - One pulse per tab: GET /api/me/pulse returns the bell's unread count, the new-challenges count, the triage attention count (null for non-admins) and the system banner. The shell polls it every 30 s while the tab is visible and not at all while hidden; a returning tab catches up at once. The bell list loads on open. The new-count and triage/attention endpoints are retired. - Indexable inbox gates: migration 0051 adds notifications.challenge_id and solution_id, derived from the payload target by a trigger and backfilled once. The visibility and trash gates, the delete cascade and mark-read-on-open now join by primary key instead of matching payload text against every challenge. One partial index replaces the two per-type payload indexes. - Role resolution: the user row, active/session check, grants, bootstrap group and people access list come back from one SQL statement, memoized for one request only. No role cache across requests; invariant 1 unchanged. Tests: unit tests for the pulse helpers and the request memo; DB tests for the one-statement resolver, the derived columns and gates, and the pulse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Three fixes from a codebase performance audit (included as
docs/performance-audit-2026-10-21.md). They cut the steady-state request and query load without changing what anyone sees. The spec change (INNOBOX_SPEC.md v0.19) was approved before implementation.1. One pulse poll per tab (§12.2)
GET /api/me/pulsereturns{ unreadCount, newChallenges, attention, banner }.attentionisnullfor non-admins.GET /api/challenges/new-countandGET /api/admin/triage/attentionare retired. The shell was their only caller.2. Indexable inbox gates (§5, §12.1, migration 0051)
notificationsgainschallenge_idandsolution_id. A trigger derives them from the payload target on insert and on payload update, and the migration backfills them once. Older link-only rows resolve from their/challenges/<n>and#SOL-<m>links.c.id::textagainst payload text, which scanned every challenge for every notification row on every 30 s poll.(user_id, challenge_id) WHERE read_at IS NULLreplaces the two per-type payload-expression indexes from 0026 and 0050.3. Role resolution in one statement (§4.2, ENTRA_AUTH_SPEC "Role staleness")
peopleaccess list come back from one SQL statement instead of 3–4 sequential ones.getSessionUseris memoized per request only, keyed on Next's per-request headers object. Nothing is reused across requests, so the "no role cache" rule and invariant 1 are unchanged.For reviewers
notifications. It runs inside the migration transaction.Testing
pnpm typecheckpasses.