diff options
author | Stan Hu <stanhu@gmail.com> | 2016-10-06 22:09:55 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-10-06 22:13:03 +0300 |
commit | aada01030cd23719a54a4e499b72c12f95ce0d24 (patch) | |
tree | cff8ffc9784c010537eb3260883074981eccd5ec /app | |
parent | 6320192592f32519c07231480cbd669a71e78320 (diff) |
Improve issue load time performance by avoiding ORDER BY in find_by call
The Sortable concern has a default scope that adds ORDER BY to all
queries. EXPLAIN ANALYZE shows that this additional ORDER BY statement
causes the SQL optimizer to use the wrong index, which leads to a load
time of 2.9 s vs 0.073 ms just for the SELECT call. The minimal
change here is to re-implement find_by using where and reorder to
remove the ORDER BY clause in IssuesController#index.
Closes #23075
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/issues_controller.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index ef13e0677d2..96041b07647 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -159,7 +159,8 @@ class Projects::IssuesController < Projects::ApplicationController protected def issue - @noteable = @issue ||= @project.issues.find_by(iid: params[:id]) || redirect_old + # The Sortable default scope causes performance issues when used with find_by + @noteable = @issue ||= @project.issues.where(iid: params[:id]).reorder(nil).take || redirect_old end alias_method :subscribable_resource, :issue alias_method :issuable, :issue |