Add optimistic lock to avoid race conditions when handling votes (#10196)
* Add optimistic lock to avoid race conditions when handling votes * Force-reload polls when getting `ActiveRecord::StaleObjectError`
This commit is contained in:
@ -32,5 +32,8 @@ class PollVote < ApplicationRecord
|
||||
def increment_counter_cache
|
||||
poll.cached_tallies[choice] = (poll.cached_tallies[choice] || 0) + 1
|
||||
poll.save
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
poll.reload
|
||||
retry
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user