Use with_lock instead of lock!
That way the record is only locked while necessary.
This commit is contained in:
@@ -18,12 +18,12 @@ class Budget
|
|||||||
before_validation :set_denormalized_ids
|
before_validation :set_denormalized_ids
|
||||||
|
|
||||||
def check_enough_resources
|
def check_enough_resources
|
||||||
ballot.lock!
|
ballot.with_lock do
|
||||||
|
|
||||||
unless ballot.enough_resources?(investment)
|
unless ballot.enough_resources?(investment)
|
||||||
errors.add(:resources, ballot.not_enough_resources_error)
|
errors.add(:resources, ballot.not_enough_resources_error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def check_valid_heading
|
def check_valid_heading
|
||||||
return if ballot.valid_heading?(heading)
|
return if ballot.valid_heading?(heading)
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ class Poll::Answer < ApplicationRecord
|
|||||||
def max_votes
|
def max_votes
|
||||||
return if !question || !author || persisted?
|
return if !question || !author || persisted?
|
||||||
|
|
||||||
author.lock!
|
author.with_lock do
|
||||||
|
|
||||||
if question.answers.by_author(author).count >= question.max_votes
|
if question.answers.by_author(author).count >= question.max_votes
|
||||||
errors.add(:answer, "Maximum number of votes per user exceeded")
|
errors.add(:answer, "Maximum number of votes per user exceeded")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user