Actions
Patch #38474
closedPreload default_status when listing trackers
Description
The patch fixes N+1 issue in TrackersController#index
.
diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb
index 64367f373..05ef336ef 100644
--- a/app/controllers/trackers_controller.rb
+++ b/app/controllers/trackers_controller.rb
@@ -26,7 +26,7 @@ class TrackersController < ApplicationController
accept_api_auth :index
def index
- @trackers = Tracker.sorted.to_a
+ @trackers = Tracker.sorted.preload(:default_status).to_a
respond_to do |format|
format.html {render :layout => false if request.xhr?}
format.api
Before:
Tracker Load (0.1ms) SELECT "trackers".* FROM "trackers" ORDER BY "trackers"."position" ASC ↳ app/controllers/trackers_controller.rb:29:in `index' Rendering trackers/index.api.rsb IssueStatus Load (0.1ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6 IssueStatus Load (0.1ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6 CACHE IssueStatus Load (0.0ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6 CACHE IssueStatus Load (0.0ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6 CACHE IssueStatus Load (0.0ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6 IssueStatus Load (0.1ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6 IssueStatus Load (0.1ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]] ↳ app/views/trackers/index.api.rsb:6
After:
Tracker Load (0.2ms) SELECT "trackers".* FROM "trackers" ORDER BY "trackers"."position" ASC ↳ app/controllers/trackers_controller.rb:29:in `index' IssueStatus Load (0.6ms) SELECT "issue_statuses".* FROM "issue_statuses" WHERE "issue_statuses"."id" IN (?, ?, ?, ?) [["id", 1], ["id", 2], ["id", 5], ["id", 3]] ↳ app/controllers/trackers_controller.rb:29:in `index'
Updated by Go MAEDA over 1 year ago
- Target version changed from Candidate for next major release to 5.1.0
Setting the target version to 5.1.0.
Updated by Go MAEDA over 1 year ago
- Status changed from New to Closed
- Assignee set to Go MAEDA
Committed the patch in r22208.
Actions