Let a day-long sync schedule replace the family sync

WO
11d ago
+462-23

Fixes #4858

Why

Every family-wide sync (nightly auto sync, the once-a-day sync on login, Sync all) requests a Plaid /transactions/refresh for every Plaid item, and Plaid bills each call. SyncSchedule can make a connection sync more often, but not less: the longest interval is 12 hours, and the family sync still syncs and refreshes every item whatever its schedule says. A household with a handful of slow-changing Plaid connections (investments, PayPal) pays for several refreshes a day it doesn't need.

What changes

  • SyncSchedule::INTERVALS gains 1, 3, 7 and 14 days. Like the existing intervals they align to multiples of the interval from the epoch, so day-long ones land at midnight UTC.
  • A schedule of a day or longer replaces the family sync for its connection: Family::Syncer#child_syncables and PlaidTransactionsRefreshAllJob leave it out (SyncSchedule.without_own_daily_schedule, matched by type and id in one subquery). SyncScheduledItemsJob syncs it when the schedule comes due, with one refresh per run as it does today.
  • Schedules shorter than a day, and connections without a schedule, behave exactly as before.
  • The per-account Sync button is unchanged, so an on-demand refresh is still one click away.
  • Labels ("Every day", "Every 3 days", ...) and the edit dialog's description in en and zh-CN.

Tests

New tests for the intervals and their alignment, replaces_family_sync?, without_own_daily_schedule (including that another provider's schedule never removes a Plaid item), the syncer leaving out a day-long-scheduled item while keeping a 12-hour one, the refresh job doing the same, and the helper labels. Ran the sync schedule, syncer, refresh, scheduled-items, sync-all, auto-sync, accounts controller and Plaid job/model tests locally: all green. Rubocop clean on the changed files.

šŸ¤– Generated with Claude Code


Summary by cubic

Lets a day-long sync schedule replace the family sync so slow-changing Plaid connections (investments, PayPal) stop paying for daily transaction refreshes they don't need (fixes #4858).

Adds 1, 3, 7, and 14 day intervals to SyncSchedule. A connection on a schedule of a day or longer is left out of the family sync, the hourly sweep, and the family-wide Plaid refresh, and is synced by SyncScheduledItemsJob when due instead. Shorter schedules, unscheduled connections, and the per-account Sync button behave as before.

  • A scheduled run whose sync couldn't be started stays due, unless its Plaid refresh was already queued — that refresh ends in a sync of its own and retrying would bill a second refresh.
  • DataCacheClearJob resyncs those items after clearing balances and holdings; FollowUpSyncJob waits until no sync is unfinished before starting a fresh one, and never starts one that would overlap a running sync.
  • Day-long intervals align to midnight UTC boundaries.

Summary by CodeRabbit

  • New Features
    • Sync schedules now offer 1-, 3-, 7-, and 14-day intervals with updated labels and guidance.
    • Connections scheduled daily or less often sync independently of family and hourly syncs. More frequent schedules continue alongside family syncs.
    • Family syncs also schedule daily-or-longer connections and rebuild their associated accounts. Scheduled Plaid refreshes occur when those connections run.
    • Follow-up syncs wait for unfinished syncs to complete before starting another.
  • Bug Fixes
    • If starting a scheduled sync fails before a refresh is queued, the original scheduled time is retained for retry.