Skip to content
Snippets Groups Projects
Commit 128a6411 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

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
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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))
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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) }
 
Loading
Loading
Loading
Loading
@@ -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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment