mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 06:21:23 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user