Commit 6f4a0a92 authored by Stan Hu's avatar Stan Hu

Eliminate N+1 queries with authors and push_data_payload in Events API

parent 5426f09f
---
title: Eliminate N+1 queries with authors and push_data_payload in Events API
merge_request:
author:
type: performance
...@@ -17,6 +17,7 @@ module API ...@@ -17,6 +17,7 @@ module API
def present_events(events) def present_events(events)
events = events.reorder(created_at: params[:sort]) events = events.reorder(created_at: params[:sort])
.with_associations
present paginate(events), with: Entities::Event present paginate(events), with: Entities::Event
end end
......
...@@ -176,7 +176,7 @@ describe API::Events do ...@@ -176,7 +176,7 @@ describe API::Events do
end end
it 'avoids N+1 queries' do 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 get api("/projects/#{private_project.id}/events", user), target_type: :merge_request
end.count end.count
...@@ -184,7 +184,7 @@ describe API::Events do ...@@ -184,7 +184,7 @@ describe API::Events do
expect do expect do
get api("/projects/#{private_project.id}/events", user), target_type: :merge_request 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 have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment