Commit 128a6411 authored by Yorick Peterse's avatar Yorick Peterse

Don't pluck project IDs for events

By instead using a sub-query we save ourselves the overhead of loading
any data into memory only to pass it on to another query.
parent eb7f6690
...@@ -36,7 +36,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -36,7 +36,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
private private
def load_events def load_events
@events = Event.in_projects(@projects.pluck(:id)) @events = Event.in_projects(@projects)
@events = @event_filter.apply_filter(@events).with_associations @events = @event_filter.apply_filter(@events).with_associations
@events = @events.limit(20).offset(params[:offset] || 0) @events = @events.limit(20).offset(params[:offset] || 0)
end end
......
...@@ -23,14 +23,14 @@ class DashboardController < Dashboard::ApplicationController ...@@ -23,14 +23,14 @@ class DashboardController < Dashboard::ApplicationController
protected protected
def load_events def load_events
project_ids = projects =
if params[:filter] == "starred" if params[:filter] == "starred"
current_user.starred_projects current_user.starred_projects
else else
current_user.authorized_projects current_user.authorized_projects
end.pluck(:id) end
@events = Event.in_projects(project_ids) @events = Event.in_projects(projects)
@events = @event_filter.apply_filter(@events).with_associations @events = @event_filter.apply_filter(@events).with_associations
@events = @events.limit(20).offset(params[:offset] || 0) @events = @events.limit(20).offset(params[:offset] || 0)
end end
......
...@@ -87,10 +87,6 @@ class GroupsController < Groups::ApplicationController ...@@ -87,10 +87,6 @@ class GroupsController < Groups::ApplicationController
@projects ||= ProjectsFinder.new.execute(current_user, group: group).sorted_by_activity.non_archived @projects ||= ProjectsFinder.new.execute(current_user, group: group).sorted_by_activity.non_archived
end end
def project_ids
@projects.pluck(:id)
end
# Dont allow unauthorized access to group # Dont allow unauthorized access to group
def authorize_read_group! def authorize_read_group!
unless @group and (@projects.present? or can?(current_user, :read_group, @group)) unless @group and (@projects.present? or can?(current_user, :read_group, @group))
...@@ -123,7 +119,7 @@ class GroupsController < Groups::ApplicationController ...@@ -123,7 +119,7 @@ class GroupsController < Groups::ApplicationController
end end
def load_events def load_events
@events = Event.in_projects(project_ids) @events = Event.in_projects(@projects)
@events = event_filter.apply_filter(@events).with_associations @events = event_filter.apply_filter(@events).with_associations
@events = @events.limit(20).offset(params[:offset] || 0) @events = @events.limit(20).offset(params[:offset] || 0)
end end
......
...@@ -47,7 +47,11 @@ class Event < ActiveRecord::Base ...@@ -47,7 +47,11 @@ class Event < ActiveRecord::Base
# Scopes # Scopes
scope :recent, -> { reorder(id: :desc) } scope :recent, -> { reorder(id: :desc) }
scope :code_push, -> { where(action: PUSHED) } scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
scope :in_projects, ->(projects) do
where(project_id: projects.reorder(nil).id_only).recent
end
scope :with_associations, -> { includes(project: :namespace) } scope :with_associations, -> { includes(project: :namespace) }
scope :for_milestone_id, ->(milestone_id) { where(target_type: "Milestone", target_id: milestone_id) } scope :for_milestone_id, ->(milestone_id) { where(target_type: "Milestone", target_id: milestone_id) }
......
...@@ -215,6 +215,8 @@ class Project < ActiveRecord::Base ...@@ -215,6 +215,8 @@ class Project < ActiveRecord::Base
scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) } scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) }
scope :non_archived, -> { where(archived: false) } scope :non_archived, -> { where(archived: false) }
scope :id_only, -> { select(:id) }
state_machine :import_status, initial: :none do state_machine :import_status, initial: :none do
event :import_start do event :import_start do
transition [:none, :finished] => :started transition [:none, :finished] => :started
......
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