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
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-06-29 17:28:16 +0300
committerDouwe Maan <douwe@gitlab.com>2017-06-29 17:28:16 +0300
commit2c879643219fdba20681bfcdd8b12d66fd2aef84 (patch)
tree3631e4e6a1508676844728eb349f2d1fdbf16e17 /app
parent3d49246dc8cd28555f7c06608fc75dcd37ee1b08 (diff)
parenta3d7983b18cc81607c255f64b678da0ab7b9477d (diff)
Merge branch 'revert-12499' into 'master'
Revert "Merge branch 'dm-drop-default-scope-on-sortable-finders' into 'master'" Closes #34511 See merge request !12557
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/issues_controller.rb2
-rw-r--r--app/models/concerns/sortable.rb23
-rw-r--r--app/models/project.rb6
3 files changed, 4 insertions, 27 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index 5b2de93c168..dfc6baa34a4 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -227,7 +227,7 @@ class Projects::IssuesController < Projects::ApplicationController
def issue
return @issue if defined?(@issue)
# The Sortable default scope causes performance issues when used with find_by
- @noteable = @issue ||= @project.issues.find_by!(iid: params[:id])
+ @noteable = @issue ||= @project.issues.where(iid: params[:id]).reorder(nil).take!
return render_404 unless can?(current_user, :read_issue, @issue)
diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb
index fdacfa5a194..a155a064032 100644
--- a/app/models/concerns/sortable.rb
+++ b/app/models/concerns/sortable.rb
@@ -5,25 +5,6 @@
module Sortable
extend ActiveSupport::Concern
- module DropDefaultScopeOnFinders
- # Override these methods to drop the `ORDER BY id DESC` default scope.
- # See http://dba.stackexchange.com/a/110919 for why we do this.
- %i[find find_by find_by!].each do |meth|
- define_method meth do |*args, &block|
- return super(*args, &block) if block
-
- unordered_relation = unscope(:order)
-
- # We cannot simply call `meth` on `unscope(:order)`, since that is also
- # an instance of the same relation class this module is included into,
- # which means we'd get infinite recursion.
- # We explicitly use the original implementation to prevent this.
- original_impl = method(__method__).super_method.unbind
- original_impl.bind(unordered_relation).call(*args)
- end
- end
- end
-
included do
# By default all models should be ordered
# by created_at field starting from newest
@@ -37,10 +18,6 @@ module Sortable
scope :order_updated_asc, -> { reorder(updated_at: :asc) }
scope :order_name_asc, -> { reorder(name: :asc) }
scope :order_name_desc, -> { reorder(name: :desc) }
-
- # All queries (relations) on this model are instances of this `relation_klass`.
- relation_klass = relation_delegate_class(ActiveRecord::Relation)
- relation_klass.prepend DropDefaultScopeOnFinders
end
module ClassMethods
diff --git a/app/models/project.rb b/app/models/project.rb
index 228f66b95cd..a75c5209955 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -815,7 +815,7 @@ class Project < ActiveRecord::Base
end
def ci_service
- @ci_service ||= ci_services.find_by(active: true)
+ @ci_service ||= ci_services.reorder(nil).find_by(active: true)
end
def deployment_services
@@ -823,7 +823,7 @@ class Project < ActiveRecord::Base
end
def deployment_service
- @deployment_service ||= deployment_services.find_by(active: true)
+ @deployment_service ||= deployment_services.reorder(nil).find_by(active: true)
end
def monitoring_services
@@ -831,7 +831,7 @@ class Project < ActiveRecord::Base
end
def monitoring_service
- @monitoring_service ||= monitoring_services.find_by(active: true)
+ @monitoring_service ||= monitoring_services.reorder(nil).find_by(active: true)
end
def jira_tracker?