Balance sheet cache layer, non-blocking sync UI #2356
Reference in New Issue
Block a user
Delete Branch "zachgoll/better-balance-sheet-caching"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR tackles two performance related issues with the accounts sidebar:
Balance sheet
This PR breaks down the
BalanceSheetinto more manageable, cacheable classes + value objects. Most notably, it introduces two key classes with aggressive caching:BalanceSheet::AccountTotals- responsible for fetching account groups, rolling up their sums with exchange rate conversion, and caching the result. This query only re-fetches when a user has an account sync that alters balance sheet data.BalanceSheet::SyncStatusMonitor- responsible for determining which of the family's accounts are currently "syncing" and should show an indicator. This is cached during idle times, and is invalidated on every sync-related event (sync started, completed, errored, etc.)The
Syncclass updatesfamily.latest_sync_activity_atandfamily.latest_sync_completed_attimestamps, which are the inputs to each of these class cache keys. The purpose of these timestamp fields is to delegate all cache-busting to the background Sync process, which allows us to avoid running "is syncing?" queries on every page load (major performance issue).Sync states UI / UX
Previously, we showed blocking sync states when accounts were running background jobs. This was a poor UI/UX pattern because when queues were blocked, running slow, or the user had a large number of accounts, the dashboard (high touchpoint view) would show what seemed to be a "stuck" loader.
The original rationale for this was—"If we don't have the latest data, don't show user anything that could be outdated or wrong". While good in theory (assuming data syncs complete quickly), this broke down in practice as we faced scaling issues with our data syncs.
New pattern: non-blocking sync status indicators
This PR introduces a much less-intrusive sync state UI/UX pattern where we show tiny loading indicators next to accounts, account groups, or charts that are currently calculating and updating data in the background. This has several benefits: