Refresh the page once after a batch of syncs finishes
GF
12d ago+400+400+012345678901234567890123456789-57-57-01234567890123456789
Before: Clicking a provider's "Sync" button in Settings > Providers, or "Sync all" on the accounts page, reloaded the page once for every connection (or manual account) as each sync finished. Every finished sync broadcast the sync toast, and the toast morph-refreshes an idle page after 2 seconds, so a batch of N syncs caused up to N full page refreshes spread over the whole batch.
After: The page refreshes once, after the last running sync of the family finishes. Account rows and the accounts page sync toolbar still update in place as each sync completes.
How
Family::SyncCompleteEventno longer broadcasts the toast itself. It schedules a debouncedFamilySyncToastJobafter the surrounding transaction commits (the event runs inside the finalizing sync's locked transaction, so a rolled-back sync leaves no job behind).- The job follows the same debounce pattern as
IdentifyRecurringTransactionsJob: a per-family cache timestamp, and only the newest scheduled run continues. It then waits (rechecking every 15 s) whileSync.for_family(family).visiblestill has running syncs, and sends the unchangedshared/notifications/sync_toastpartial once they are done. Sync.visibleignores cancelled syncs and syncs older thanSync::VISIBLE_FOR, so a sync whose worker died delays the toast by at most 5 minutes.MAX_RECHECKSis only a safety net.- Trade-off: a single sync now shows the toast about 10 s after it finishes instead of right away. Near-simultaneous duplicate broadcasts are harmless, because replacing
#sync-toastdisconnects the previoussync-toastcontroller, and itsdisconnect()clears the pending refresh timer. - The debounce needs a shared cache store across Sidekiq workers (Redis in production, as for the recurring transaction job). With
:null_storeit falls back to one toast per sync, which is the current behavior.
Related history: #1964 introduced the toast. It solved stacking by replacing a fixed id, but every replace re-arms the auto-refresh.
Validation
- New
test/jobs/family_sync_toast_job_test.rb: sends when idle, reschedules while another sync of the family runs, stops at the safety limit, is superseded by a newer run, ignores other families, cancelled syncs and syncs hung past the visibility window, a crashed sync delays the toast only until it leaves the window, and a missing family is a no-op. - Updated
test/models/family/sync_complete_event_test.rb: the sync controls are still replaced, the toast is not broadcast directly, and the job is enqueued only after the transaction commits. All three tests fail onmain. - The provider sync-complete event tests from #4046 now perform the toast job inside their broadcast capture, so they still assert that the toast is sent and that no stream carries the provider card.
- Full
bin/rails test: 11831 runs, 0 failures, 0 errors. - Rubocop, erb_lint, Biome and Brakeman are clean.
Summary by CodeRabbit
- New Features
- Sync completion notifications now wait briefly for other active syncs in the family to finish before appearing.
- Notifications update to reflect newer syncs, and delayed checks stop after a set limit.
- If a family is no longer available or a newer sync takes over, the outdated notification is not shown.
- Account sync controls continue to refresh when a sync completes.