Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/route.rb')
-rw-r--r--app/models/route.rb44
1 files changed, 27 insertions, 17 deletions
diff --git a/app/models/route.rb b/app/models/route.rb
index 652c33a673c..1fa0005ffb4 100644
--- a/app/models/route.rb
+++ b/app/models/route.rb
@@ -3,6 +3,7 @@
class Route < MainClusterwide::ApplicationRecord
include CaseSensitivity
include Gitlab::SQL::Pattern
+ include EachBatch
belongs_to :source, polymorphic: true, inverse_of: :route # rubocop:disable Cop/PolymorphicAssociations
belongs_to :namespace, inverse_of: :namespace_route
@@ -26,30 +27,39 @@ class Route < MainClusterwide::ApplicationRecord
def rename_descendants
return unless saved_change_to_path? || saved_change_to_name?
- descendant_routes = self.class.inside_path(path_before_last_save)
+ if Feature.disabled?(:batch_route_updates, Feature.current_request, type: :gitlab_com_derisk)
+ descendant_routes = self.class.inside_path(path_before_last_save)
- descendant_routes.each do |route|
- attributes = {}
+ descendant_routes.each do |route|
+ attributes = {}
- if saved_change_to_path? && route.path.present?
- attributes[:path] = route.path.sub(path_before_last_save, path)
- end
+ if saved_change_to_path? && route.path.present?
+ attributes[:path] = route.path.sub(path_before_last_save, path)
+ end
- if saved_change_to_name? && name_before_last_save.present? && route.name.present?
- attributes[:name] = route.name.sub(name_before_last_save, name)
- end
+ if saved_change_to_name? && name_before_last_save.present? && route.name.present?
+ attributes[:name] = route.name.sub(name_before_last_save, name)
+ end
- next if attributes.empty?
+ next if attributes.empty?
- old_path = route.path
+ old_path = route.path
- # Callbacks must be run manually
- route.update_columns(attributes.merge(updated_at: Time.current))
+ # Callbacks must be run manually
+ route.update_columns(attributes.merge(updated_at: Time.current))
+
+ # We are not calling route.delete_conflicting_redirects here, in hopes
+ # of avoiding deadlocks. The parent (self, in this method) already
+ # called it, which deletes conflicts for all descendants.
+ route.create_redirect(old_path) if attributes[:path]
+ end
+ else
+ changes = {
+ path: { saved: saved_change_to_path?, old_value: path_before_last_save },
+ name: { saved: saved_change_to_name?, old_value: name_before_last_save }
+ }
- # We are not calling route.delete_conflicting_redirects here, in hopes
- # of avoiding deadlocks. The parent (self, in this method) already
- # called it, which deletes conflicts for all descendants.
- route.create_redirect(old_path) if attributes[:path]
+ Routes::RenameDescendantsService.new(self).execute(changes) # rubocop: disable CodeReuse/ServiceClass -- Need a service class to encapsulate all the logic.
end
end