app/models/user.rb
# Note: Using a lock to prevent race conditions from saving a wrong value.
Using a lock to prevent race conditions from saving a wrong value.
Using a lock to prevent race conditions from saving a wrong value .
def update_used_storage(add: nil, remove: nil)
    with_lock do
      self.used_storage += add if add
      self.used_storage -= remove if remove
      self.used_storage = 0 if used_storage.negative?
      save!
    end
  end
def update_used_storage ( add : nil , remove : nil ) with_lock do self . used_storage += add if add self . used_storage -= remove if remove self . used_storage = 0 if used_storage . negative? save! end end
Note: Using a lock to prevent race conditions from saving a wrong value.
Note : Using a lock to prevent race conditions from saving a wrong value .
add
<not_specific>
remove
<not_specific>