mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
Balance sheet cache layer, non-blocking sync UI (#2356)
* Balance sheet cache layer with cache-busting * Update family cache timestamps during Sync * Less blocking sync loaders * Consolidate family data caching key logic * Fix turbo stream broadcasts * Remove dev delay * Add back account group sorting
This commit is contained in:
parent
dab693d74f
commit
10ce2c8e23
35 changed files with 529 additions and 466 deletions
|
@ -2,25 +2,24 @@ class AccountableSparklinesController < ApplicationController
|
|||
def show
|
||||
@accountable = Accountable.from_type(params[:accountable_type]&.classify)
|
||||
|
||||
# Pre-load the series to catch any errors before rendering
|
||||
@series = Rails.cache.fetch(cache_key) do
|
||||
account_ids = family.accounts.active.where(accountable_type: @accountable.name).pluck(:id)
|
||||
etag_key = cache_key
|
||||
|
||||
builder = Balance::ChartSeriesBuilder.new(
|
||||
account_ids: account_ids,
|
||||
currency: family.currency,
|
||||
period: Period.last_30_days,
|
||||
favorable_direction: @accountable.favorable_direction,
|
||||
interval: "1 day"
|
||||
)
|
||||
# Use HTTP conditional GET so the client receives 304 Not Modified when possible.
|
||||
if stale?(etag: etag_key, last_modified: family.latest_sync_completed_at)
|
||||
@series = Rails.cache.fetch(etag_key, expires_in: 24.hours) do
|
||||
builder = Balance::ChartSeriesBuilder.new(
|
||||
account_ids: account_ids,
|
||||
currency: family.currency,
|
||||
period: Period.last_30_days,
|
||||
favorable_direction: @accountable.favorable_direction,
|
||||
interval: "1 day"
|
||||
)
|
||||
|
||||
builder.balance_series
|
||||
builder.balance_series
|
||||
end
|
||||
|
||||
render layout: false
|
||||
end
|
||||
|
||||
render layout: false
|
||||
rescue => e
|
||||
Rails.logger.error "Accountable sparkline error for #{@accountable&.name}: #{e.message}"
|
||||
render partial: "accountable_sparklines/error", layout: false
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -28,7 +27,15 @@ class AccountableSparklinesController < ApplicationController
|
|||
Current.family
|
||||
end
|
||||
|
||||
def accountable
|
||||
Accountable.from_type(params[:accountable_type]&.classify)
|
||||
end
|
||||
|
||||
def account_ids
|
||||
family.accounts.active.where(accountable_type: accountable.name).pluck(:id)
|
||||
end
|
||||
|
||||
def cache_key
|
||||
family.build_cache_key("#{@accountable.name}_sparkline")
|
||||
family.build_cache_key("#{@accountable.name}_sparkline", invalidate_on_data_updates: true)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue