Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2019-03-02 03:37:23 +0300
committerRobert Speicher <rspeicher@gmail.com>2019-03-02 03:37:23 +0300
commitc1b50f858f94ee81b375ab80d1273b1e31a38307 (patch)
tree1a277de753cf0e0265d87a51a5d3e586ffa134ec
parent5c9aa45489aee7cd1edaa15a30fb8a3aa24417a8 (diff)
parenta769292c672dea9fae702dd75f643a14752110ee (diff)
Merge branch 'sh-optimize-calendar-activities' into 'master'
Eliminate most N+1 queries loading UserController#calendar_activities Closes #58392 See merge request gitlab-org/gitlab-ce!25697
-rw-r--r--changelogs/unreleased/sh-optimize-calendar-activities.yml5
-rw-r--r--lib/gitlab/contributions_calendar.rb1
-rw-r--r--spec/controllers/users_controller_spec.rb34
3 files changed, 37 insertions, 3 deletions
diff --git a/changelogs/unreleased/sh-optimize-calendar-activities.yml b/changelogs/unreleased/sh-optimize-calendar-activities.yml
new file mode 100644
index 00000000000..b8500357e17
--- /dev/null
+++ b/changelogs/unreleased/sh-optimize-calendar-activities.yml
@@ -0,0 +1,5 @@
+---
+title: Eliminate most N+1 queries loading UserController#calendar_activities
+merge_request: 25697
+author:
+type: performance
diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb
index 5ed6427072a..f7d046600e8 100644
--- a/lib/gitlab/contributions_calendar.rb
+++ b/lib/gitlab/contributions_calendar.rb
@@ -49,6 +49,7 @@ module Gitlab
Event.contributions.where(author_id: contributor.id)
.where(created_at: date.beginning_of_day..date.end_of_day)
.where(project_id: projects)
+ .with_associations
end
# rubocop: enable CodeReuse/ActiveRecord
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index af61026098b..4f6a6881193 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -185,13 +185,32 @@ describe UsersController do
context 'for user' do
context 'with public profile' do
- it 'renders calendar_activities' do
- push_data = Gitlab::DataBuilder::Push.build_sample(project, public_user)
- EventCreateService.new.push(project, public_user, push_data)
+ let(:issue) { create(:issue, project: project, author: user) }
+ let(:note) { create(:note, noteable: issue, author: user, project: project) }
+
+ render_views
+
+ before do
+ create_push_event
+ create_note_event
+ end
+ it 'renders calendar_activities' do
get :calendar_activities, params: { username: public_user.username }
+
expect(assigns[:events]).not_to be_empty
end
+
+ it 'avoids N+1 queries', :request_store do
+ get :calendar_activities, params: { username: public_user.username }
+
+ control = ActiveRecord::QueryRecorder.new { get :calendar_activities, params: { username: public_user.username } }
+
+ create_push_event
+ create_note_event
+
+ expect { get :calendar_activities, params: { username: public_user.username } }.not_to exceed_query_limit(control)
+ end
end
context 'with private profile' do
@@ -203,6 +222,15 @@ describe UsersController do
expect(response).to have_gitlab_http_status(:not_found)
end
end
+
+ def create_push_event
+ push_data = Gitlab::DataBuilder::Push.build_sample(project, public_user)
+ EventCreateService.new.push(project, public_user, push_data)
+ end
+
+ def create_note_event
+ EventCreateService.new.leave_note(note, public_user)
+ end
end
end