diff options
author | Rémy Coutable <remy@rymai.me> | 2018-06-05 18:22:04 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-06-05 18:22:04 +0300 |
commit | 6153a61633b7cd3e2e13c09065c0ead081644e3e (patch) | |
tree | 11c7226e7128cd5e2aa5f704487f5bf72cfb0c6c | |
parent | 4deded6ef2f620dfb44cf4f079a78b245f69b3f0 (diff) | |
parent | 6f4a0a92e6331b7033a8165c5b5e9cc7b0f880c2 (diff) |
Merge branch 'sh-fix-events-nplus-one' into 'master'
Eliminate N+1 queries with authors and push_data_payload in Events API
See merge request gitlab-org/gitlab-ce!19347
-rw-r--r-- | changelogs/unreleased/sh-fix-events-nplus-one.yml | 5 | ||||
-rw-r--r-- | lib/api/events.rb | 1 | ||||
-rw-r--r-- | spec/requests/api/events_spec.rb | 4 |
3 files changed, 8 insertions, 2 deletions
diff --git a/changelogs/unreleased/sh-fix-events-nplus-one.yml b/changelogs/unreleased/sh-fix-events-nplus-one.yml new file mode 100644 index 00000000000..e5a974bef30 --- /dev/null +++ b/changelogs/unreleased/sh-fix-events-nplus-one.yml @@ -0,0 +1,5 @@ +--- +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 |