Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-06-28 11:14:09 +0300
committerThong Kuah <tkuah@gitlab.com>2019-06-28 11:14:09 +0300
commitd69f9af7cf4d208a87379a211ff63fc7f1e5fce4 (patch)
treeeb808417379c5b35b49b11a108b7b5d37087866f /app
parentb0845b6293cc31f29583116ab583e77aad6a892f (diff)
parent04d2d8f9b7e8593cb0ea3d8db7b57b843387fa2b (diff)
Merge branch '63212-n-1-queries-in-projects-id-boards-api' into 'master'
Remove N+1 queries in boards API See merge request gitlab-org/gitlab-ce!29634
Diffstat (limited to 'app')
-rw-r--r--app/models/board.rb5
-rw-r--r--app/models/list.rb1
2 files changed, 5 insertions, 1 deletions
diff --git a/app/models/board.rb b/app/models/board.rb
index e08db764f65..50b6ca9b70f 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -4,11 +4,14 @@ class Board < ApplicationRecord
belongs_to :group
belongs_to :project
- has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
+ has_many :lists, -> { ordered }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
+ has_many :destroyable_lists, -> { destroyable.ordered }, class_name: "List"
validates :project, presence: true, if: :project_needed?
validates :group, presence: true, unless: :project
+ scope :with_associations, -> { preload(:destroyable_lists) }
+
def project_needed?
!group
end
diff --git a/app/models/list.rb b/app/models/list.rb
index 17b1a8510cf..d28a9bda82d 100644
--- a/app/models/list.rb
+++ b/app/models/list.rb
@@ -16,6 +16,7 @@ class List < ApplicationRecord
scope :destroyable, -> { where(list_type: list_types.slice(*destroyable_types).values) }
scope :movable, -> { where(list_type: list_types.slice(*movable_types).values) }
scope :preload_associations, -> { preload(:board, :label) }
+ scope :ordered, -> { order(:list_type, :position) }
class << self
def destroyable_types