summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-06-03 04:36:22 -0700
committerStan Hu <stanhu@gmail.com>2018-06-04 21:53:59 -0700
commita3f75a316404c79a85ecc2852030491056bfe212 (patch)
treecdb8625f9bae8af16e3a74d14a89d71c6800d6be
parent16e5c3565c7434c47ebe8b5c72fbc77787f4fb0d (diff)
downloadgitlab-ce-sh-fix-events-nplus-one.tar.gz
Eliminate N+1 queries with authors and push_data_payload in Events APIsh-fix-events-nplus-one
-rw-r--r--changelogs/unreleased/sh-add-uncached-query-limiter.yml2
-rw-r--r--lib/api/events.rb1
-rw-r--r--spec/requests/api/events_spec.rb4
3 files changed, 4 insertions, 3 deletions
diff --git a/changelogs/unreleased/sh-add-uncached-query-limiter.yml b/changelogs/unreleased/sh-add-uncached-query-limiter.yml
index 4318338c229..e5a974bef30 100644
--- a/changelogs/unreleased/sh-add-uncached-query-limiter.yml
+++ b/changelogs/unreleased/sh-add-uncached-query-limiter.yml
@@ -1,5 +1,5 @@
---
-title: Remove N+1 query for author in issues API
+title: Eliminate N+1 queries with authors and push_data_payload in Events API
merge_request:
author:
type: performance
diff --git a/lib/api/events.rb b/lib/api/events.rb
index b0713ff1d54..fc4ba5a3188 100644
--- a/lib/api/events.rb
+++ b/lib/api/events.rb
@@ -17,6 +17,7 @@ module API
def present_events(events)
events = events.reorder(created_at: params[:sort])
+ .with_associations
present paginate(events), with: Entities::Event
end
diff --git a/spec/requests/api/events_spec.rb b/spec/requests/api/events_spec.rb
index 962c845f36d..e6a61fdcf39 100644
--- a/spec/requests/api/events_spec.rb
+++ b/spec/requests/api/events_spec.rb
@@ -176,7 +176,7 @@ describe API::Events do
end
it 'avoids N+1 queries' do
- control_count = ActiveRecord::QueryRecorder.new do
+ control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
get api("/projects/#{private_project.id}/events", user), target_type: :merge_request
end.count
@@ -184,7 +184,7 @@ describe API::Events do
expect do
get api("/projects/#{private_project.id}/events", user), target_type: :merge_request
- end.not_to exceed_query_limit(control_count)
+ end.not_to exceed_all_query_limit(control_count)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers