Wrap join code redemption in a lock

This commit is contained in:
Stanko K.R.
2025-12-12 09:59:42 +01:00
parent 0e70ab18e8
commit c8a5d01771
+2 -2
View File
@@ -11,8 +11,8 @@ class Account::JoinCode < ApplicationRecord
before_create :generate_code, if: -> { code.blank? }
def redeem_if(&block)
transaction do
increment!(:usage_count) if block.call(account)
with_lock do
increment!(:usage_count) if active? && block.call(account)
end
end