diff options
| author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-01-25 16:56:23 +0100 |
|---|---|---|
| committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-01-26 10:51:53 +0100 |
| commit | 128a6411d2a60c855e3c99303d0157f436e32f13 (patch) | |
| tree | 6affd244fa7353f7629bb567b2dcad6ca5c4b3bd /app/models | |
| parent | eb7f669073b2b95a1956de5e22f97dc8f83711e8 (diff) | |
| download | gitlab-ce-128a6411d2a60c855e3c99303d0157f436e32f13.tar.gz | |
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.
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/event.rb | 6 | ||||
| -rw-r--r-- | app/models/project.rb | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index 01d008035a5..8dfc1d04709 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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) } diff --git a/app/models/project.rb b/app/models/project.rb index 4bd51449c25..63ecf5b7105 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 |
