diff options
author | charlieablett <cablett@gitlab.com> | 2019-06-14 01:20:03 +0300 |
---|---|---|
committer | charlieablett <cablett@gitlab.com> | 2019-06-26 02:47:18 +0300 |
commit | 426f1c20b19e5bd98ee0ab8bd5f8851b683a79c6 (patch) | |
tree | 14dfe36a0f72fa5fee258f7a89f94c74be6720f4 /app/models/board.rb | |
parent | 4633df7b9e756ae50f35246e9ba93e1c3ca1e01a (diff) |
Remove N+1 query for project and group boards
- Add test for N+1 queries
- Add destroyable lists scope to Board and List
- Preload lists for both project and group boards
Diffstat (limited to 'app/models/board.rb')
-rw-r--r-- | app/models/board.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/app/models/board.rb b/app/models/board.rb index e08db764f65..891d26897ed 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -5,10 +5,13 @@ class Board < ApplicationRecord belongs_to :project has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent + has_many :destroyable_lists, -> { destroyable }, 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 |