gitlab-org--gitlab-foss/lib/gitlab/optimistic_locking.rb
Kamil Trzciński 650f40865e Forbid the use of #reload and prefer #reset
The `#reload` makes to load all objects into memory,
and the main purpose of `#reload` is to drop the association cache.

The `#reset` seems to solve exactly that case.
2019-04-15 13:05:14 +02:00

21 lines
415 B
Ruby

# frozen_string_literal: true
module Gitlab
module OptimisticLocking
module_function
def retry_lock(subject, retries = 100, &block)
ActiveRecord::Base.transaction do
yield(subject)
end
rescue ActiveRecord::StaleObjectError
retries -= 1
raise unless retries >= 0
subject.reset
retry
end
alias_method :retry_optimistic_lock, :retry_lock
end
end