Skip unnecessary sync when account balance unchanged on update (#1040)

The update action was calling set_current_balance (which triggers
sync_later internally) on every form submission, even when the balance
hadn't changed. This caused the account to enter a syncing state,
replacing the visible balance with a pulsing skeleton placeholder
until the sync completed.

Now we compare the submitted balance against the current value and
only call set_current_balance when it actually differs. Also removes
a redundant sync_later call that duplicated the one already inside
set_current_balance.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Rowberg
2026-02-21 09:47:31 -05:00
committed by GitHub
parent 1881606786
commit b1b2793e43

View File

@@ -41,15 +41,14 @@ module AccountableResource
end
def update
# Handle balance update if provided
if account_params[:balance].present?
# Handle balance update if the value actually changed
if account_params[:balance].present? && account_params[:balance].to_d != @account.balance
result = @account.set_current_balance(account_params[:balance].to_d)
unless result.success?
@error_message = result.error_message
render :edit, status: :unprocessable_entity
return
end
@account.sync_later
end
# Update remaining account attributes