Stop broadcasting account rows to the whole family
Summary
Every account sync rendered the accounts/_account row, with the account's name and balance, and broadcast it on the family Turbo stream. Every signed-in family member subscribes to that stream, including members the account isn't shared with, so the row reached their browser even though /accounts doesn't show it to them. This PR removes the row broadcast and lets the family sync toast, which makes each browser re-fetch its own page, carry the update.
Closes #4047
Fork pre-flight PR: jaysbeekay/sure#354 (same branch, same commit; its CI and review history are there).
What changed
Account::SyncCompleteEvent#broadcast:
- The
broadcast_replace_to(account.family, target: "account_#{id}", partial: "accounts/account")is removed. account.family.broadcast_sync_completeis now sent for every account, not only unlinked ones. A linked account can sync on its own, throughSync#perform_post_sync, with no provider event after it. Without the toast,/accountswould stay stale once the row replace is gone.account.broadcast_refreshon the account's own stream is unchanged. Only viewers who opened that account's page hold that stream.
Deliberately not changed:
- Provider card broadcasts: #4046.
- The manual accounts list rebuilt by provider controllers: #4049.
- Per-user streams. That's a bigger change than this needs.
Demo data
No demo data needed.
Screenshots
No visual change. The row on /accounts updates through the existing sync toast instead of an in-place replace.
Migration notes
No migration.
Verification
Tests were written first (test/models/account/sync_complete_event_test.rb, new). On main (a92dec1e6), two fail:
- "an account sync does not broadcast the rendered row to the family":
account_<id>was among the targets. - "a linked account syncing alone still sends the family toast": only the row was sent.
These pass before and after, as guards should:
- "an unlinked account still sends the family toast";
- "the account page still refreshes on its own stream".
Breaking the fix on purpose fails a test each time:
| Breakage | Caught by |
|---|---|
| Row replace put back | does not broadcast the rendered row |
Toast made unless account.linked? again | linked account syncing alone still sends the toast |
account.broadcast_refresh removed | the account page still refreshes |
Commands:
bin/rails teston0f111aecc: 10,837 runs, 46,205 assertions, 0 failures, 0 errors, 33 skips.bin/rubocopon the changed files: no offenses.bin/brakeman --no-pager: 0 warnings.- No ERB or JavaScript changed.
Blast radius
Account#broadcast_sync_complete is called by:
Sync#perform_post_sync;- every provider
SyncCompleteEvent, once per linked account; - several provider account processors and activity jobs.
All of them pass a single account and none reads a return value. Each call now produces one family toast. A provider sync therefore sends the toast once per account plus once from the item event:
- The toast and the sync controls contain no account data.
- Each replace re-arms the same
sync-toastelement, so the browser still refreshes once. - The recurring-transaction pass the toast schedules is debounced (
IdentifyRecurringTransactionsJob.schedule_for).
accounts/_account is still rendered in requests by accounts/index/_account_groups, which is the per-viewer path.
Summary by CodeRabbit
- Bug Fixes
- Family members now receive a sync-complete notification whether the account is linked or unlinked.
- The family notification no longer includes an account row or account name. The account page still refreshes when synchronization completes.