Fix export dossier n+1 query

This commit is contained in:
Paul Chavard 2019-07-30 15:39:20 +02:00
parent 5a9468aa95
commit ab1170bcfc

View file

@ -108,7 +108,24 @@ class Dossier < ApplicationRecord
scope :en_construction, -> { not_archived.state_en_construction }
scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine }
scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :user, :individual, :followers_gestionnaires, :avis, champs: { etablissement: [:champ], type_de_champ: :drop_down_list }, champs_private: { etablissement: [:champ], type_de_champ: :drop_down_list }).order(en_construction_at: 'asc') }
scope :downloadable_sorted, -> {
state_not_brouillon
.includes(
:user,
:individual,
:followers_gestionnaires,
:avis,
etablissement: :champ,
champs: {
etablissement: :champ,
type_de_champ: :drop_down_list
},
champs_private: {
etablissement: :champ,
type_de_champ: :drop_down_list
}
).order(en_construction_at: 'asc')
}
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }