Stop broadcasting account rows to the whole family

Closed
JA
2mo ago
+61-13

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.

Part of jaysbeekay/sure#235 (fork issue). Upstream issue: we-promise/sure#4047.

Upstream PR: we-promise/sure#4050 (same branch, same commit).

What changed

Account::SyncCompleteEvent#broadcast:

  • The broadcast_replace_to(account.family, target: "account_#{id}", partial: "accounts/account") is removed.
  • account.family.broadcast_sync_complete is now sent for every account, not only unlinked ones. A linked account can sync on its own, through Sync#perform_post_sync, with no provider event after it. Without the toast, /accounts would stay stale once the row replace is gone.
  • account.broadcast_refresh on the account's own stream is unchanged. Only viewers who opened that account's page hold that stream.

Deliberately not changed:

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:

BreakageCaught by
Row replace put backdoes not broadcast the rendered row
Toast made unless account.linked? againlinked account syncing alone still sends the toast
account.broadcast_refresh removedthe account page still refreshes

Commands:

  • bin/rails test on 0f111aecc: 10,837 runs, 46,205 assertions, 0 failures, 0 errors, 33 skips.
  • bin/rubocop on 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-toast element, 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.