summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-02-13 18:11:26 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-02-13 18:11:26 +0000
commit44406ae8db5587eabda2c69aef886f8c512b2ac3 (patch)
treee11ecf4696389f78f89952011759d59c393d09ce
parent122ffd9fc799ab9a99cc555e4a82b68bcffabb0f (diff)
parent1698d71ccfce229b8d7c36a87a67764d53e97c8b (diff)
downloadgitlab-ce-44406ae8db5587eabda2c69aef886f8c512b2ac3.tar.gz
Merge branch '27395-reduce-group-activity-sql-queries' into 'master'
Resolve "GroupsController#activity.json is REALLY slow due to SQL" Closes #27395 See merge request !9088
-rw-r--r--app/controllers/dashboard/projects_controller.rb23
-rw-r--r--app/models/event.rb4
-rw-r--r--changelogs/unreleased/27395-reduce-group-activity-sql-queries-2.yml4
-rw-r--r--changelogs/unreleased/27395-reduce-group-activity-sql-queries.yml4
4 files changed, 21 insertions, 14 deletions
diff --git a/app/controllers/dashboard/projects_controller.rb b/app/controllers/dashboard/projects_controller.rb
index 3ba8c2f8bb9..325ae565537 100644
--- a/app/controllers/dashboard/projects_controller.rb
+++ b/app/controllers/dashboard/projects_controller.rb
@@ -1,19 +1,14 @@
class Dashboard::ProjectsController < Dashboard::ApplicationController
include FilterProjects
- before_action :event_filter
-
def index
- @projects = current_user.authorized_projects.sorted_by_activity
- @projects = filter_projects(@projects)
- @projects = @projects.includes(:namespace)
+ @projects = load_projects(current_user.authorized_projects)
@projects = @projects.sort(@sort = params[:sort])
@projects = @projects.page(params[:page])
respond_to do |format|
format.html { @last_push = current_user.recent_push }
format.atom do
- event_filter
load_events
render layout: false
end
@@ -26,9 +21,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
def starred
- @projects = current_user.viewable_starred_projects.sorted_by_activity
- @projects = filter_projects(@projects)
- @projects = @projects.includes(:namespace, :forked_from_project, :tags)
+ @projects = load_projects(current_user.viewable_starred_projects)
+ @projects = @projects.includes(:forked_from_project, :tags)
@projects = @projects.sort(@sort = params[:sort])
@projects = @projects.page(params[:page])
@@ -37,7 +31,6 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
respond_to do |format|
format.html
-
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
@@ -48,9 +41,15 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
private
+ def load_projects(base_scope)
+ projects = base_scope.sorted_by_activity.includes(:namespace)
+
+ filter_projects(projects)
+ end
+
def load_events
- @events = Event.in_projects(@projects)
- @events = @event_filter.apply_filter(@events).with_associations
+ @events = Event.in_projects(load_projects(current_user.authorized_projects))
+ @events = event_filter.apply_filter(@events).with_associations
@events = @events.limit(20).offset(params[:offset] || 0)
end
end
diff --git a/app/models/event.rb b/app/models/event.rb
index 2662f170765..cf89ac5207f 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -36,10 +36,10 @@ class Event < ActiveRecord::Base
scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(projects) do
- where(project_id: projects.map(&:id)).recent
+ where(project_id: projects).recent
end
- scope :with_associations, -> { includes(project: :namespace) }
+ scope :with_associations, -> { includes(:author, :project, project: :namespace).preload(:target) }
scope :for_milestone_id, ->(milestone_id) { where(target_type: "Milestone", target_id: milestone_id) }
class << self
diff --git a/changelogs/unreleased/27395-reduce-group-activity-sql-queries-2.yml b/changelogs/unreleased/27395-reduce-group-activity-sql-queries-2.yml
new file mode 100644
index 00000000000..f3ce1709518
--- /dev/null
+++ b/changelogs/unreleased/27395-reduce-group-activity-sql-queries-2.yml
@@ -0,0 +1,4 @@
+---
+title: Include :author, :project, and :target in Event.with_associations
+merge_request:
+author:
diff --git a/changelogs/unreleased/27395-reduce-group-activity-sql-queries.yml b/changelogs/unreleased/27395-reduce-group-activity-sql-queries.yml
new file mode 100644
index 00000000000..3f6d922f2a0
--- /dev/null
+++ b/changelogs/unreleased/27395-reduce-group-activity-sql-queries.yml
@@ -0,0 +1,4 @@
+---
+title: Don't instantiate AR objects in Event.in_projects
+merge_request:
+author: