diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-16 12:09:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-16 12:09:22 +0000 |
commit | 9d67bc14cb59a27c9877474e77d155173a1dedff (patch) | |
tree | fae9da04bb838c0bf93df6ba7669c15413e99f8e /config | |
parent | 9c7b3812a22465b77ee24657ad1b446b81ffbc74 (diff) | |
download | gitlab-ce-9d67bc14cb59a27c9877474e77d155173a1dedff.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/config_initializers_active_record_locking.rb | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/config/initializers/config_initializers_active_record_locking.rb b/config/initializers/config_initializers_active_record_locking.rb deleted file mode 100644 index 9f9908283c6..00000000000 --- a/config/initializers/config_initializers_active_record_locking.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -# ensure ActiveRecord's version has been required already -require 'active_record/locking/optimistic' - -# rubocop:disable Lint/RescueException -module ActiveRecord - module Locking - module Optimistic - private - - def _update_row(attribute_names, attempted_action = "update") - return super unless locking_enabled? - - begin - locking_column = self.class.locking_column - previous_lock_value = read_attribute_before_type_cast(locking_column) - attribute_names << locking_column - - self[locking_column] += 1 - - # Patched because when `lock_version` is read as `0`, it may actually be `NULL` in the DB. - possible_previous_lock_value = previous_lock_value.to_i == 0 ? [nil, 0] : previous_lock_value - - affected_rows = self.class.unscoped.where( - locking_column => possible_previous_lock_value, - self.class.primary_key => id_in_database - ).update_all( - attributes_with_values(attribute_names) - ) - - if affected_rows != 1 - raise ActiveRecord::StaleObjectError.new(self, attempted_action) - end - - affected_rows - - # If something went wrong, revert the locking_column value. - rescue Exception - self[locking_column] = previous_lock_value.to_i - raise - end - end - end - end -end |