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.
This commit is contained in:
parent
eb7f669073
commit
128a6411d2
|
@ -36,7 +36,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
|
|||
private
|
||||
|
||||
def load_events
|
||||
@events = Event.in_projects(@projects.pluck(:id))
|
||||
@events = Event.in_projects(@projects)
|
||||
@events = @event_filter.apply_filter(@events).with_associations
|
||||
@events = @events.limit(20).offset(params[:offset] || 0)
|
||||
end
|
||||
|
|
|
@ -23,14 +23,14 @@ class DashboardController < Dashboard::ApplicationController
|
|||
protected
|
||||
|
||||
def load_events
|
||||
project_ids =
|
||||
projects =
|
||||
if params[:filter] == "starred"
|
||||
current_user.starred_projects
|
||||
else
|
||||
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 = @events.limit(20).offset(params[:offset] || 0)
|
||||
end
|
||||
|
|
|
@ -87,10 +87,6 @@ class GroupsController < Groups::ApplicationController
|
|||
@projects ||= ProjectsFinder.new.execute(current_user, group: group).sorted_by_activity.non_archived
|
||||
end
|
||||
|
||||
def project_ids
|
||||
@projects.pluck(:id)
|
||||
end
|
||||
|
||||
# Dont allow unauthorized access to group
|
||||
def authorize_read_group!
|
||||
unless @group and (@projects.present? or can?(current_user, :read_group, @group))
|
||||
|
@ -123,7 +119,7 @@ class GroupsController < Groups::ApplicationController
|
|||
end
|
||||
|
||||
def load_events
|
||||
@events = Event.in_projects(project_ids)
|
||||
@events = Event.in_projects(@projects)
|
||||
@events = event_filter.apply_filter(@events).with_associations
|
||||
@events = @events.limit(20).offset(params[:offset] || 0)
|
||||
end
|
||||
|
|
|
@ -47,7 +47,11 @@ class Event < ActiveRecord::Base
|
|||
# Scopes
|
||||
scope :recent, -> { reorder(id: :desc) }
|
||||
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 :for_milestone_id, ->(milestone_id) { where(target_type: "Milestone", target_id: milestone_id) }
|
||||
|
||||
|
|
|
@ -215,6 +215,8 @@ class Project < ActiveRecord::Base
|
|||
scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) }
|
||||
scope :non_archived, -> { where(archived: false) }
|
||||
|
||||
scope :id_only, -> { select(:id) }
|
||||
|
||||
state_machine :import_status, initial: :none do
|
||||
event :import_start do
|
||||
transition [:none, :finished] => :started
|
||||
|
|
Loading…
Reference in New Issue