fix(mining): gate /contacts person INSERT realtime by active mining - #2884
Merged
Conversation
The contacts channel subscribed to all person changes, so background/passive mining flooded the client and the realtime tenant (dropping profile/credits events). The postgres_changes filter set is fixed at subscribe time, so: - add buildPersonChangeFilters(): UPDATE+DELETE always, INSERT only while a foreground mining is active; - rebuild the channel when activeMiningTask flips so the server-side filter stops delivering INSERTs outside foreground mining (keep-last; new contacts appear on reload/page entry).
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.
Summary
Split from #2881 (now closed): the frontend half, extracted so it can land independently of the refine-persons SQL changes in #2883.
The contacts page subscribed to all
personschanges (event: '*'), so background/passive mining streamed every new person INSERT into the client — flooding /contacts mid-session and starving other realtime channels on the tenant (credits-profile, etc.), surfacing asMessagePerSecondRateLimitReached.Key changes
buildPersonChangeFilters()incontacts-realtime.ts: the channel listensUPDATE+DELETEalways, andINSERTonly while a foreground mining is active.createContactsRealtimeChannel()and rebuilds it whenactiveMiningTaskflips — the postgres_changes filter set is fixed at subscribe time, so rebuilding is the only way to toggle the INSERT listener server-side (new contacts mined in the background appear on reload/page entry).handlePersonRealtimeEvent()/syncRealtimeInsertListener()in the store; the non-gating behavior (reconcile path, UPDATE/DELETE) is unchanged.buildPersonChangeFilters(INSERT excluded when idle, included while mining).Notes
IS DISTINCT FROMchange-guard on the person upsert (server-side suppression of no-op UPDATE events) — together they cut the realtime flood at both ends.Testing
npm run test -- --run src/tests/unit/contacts-realtime.test.ts— 17/17 green; prettier + eslint clean (0 errors).Resolves #2867.