fix(instructeur): avoid n+1 in instructeur_dossier#show and user_dossier#show
This commit is contained in:
parent
8b1af41273
commit
77c2187747
2 changed files with 41 additions and 32 deletions
|
@ -43,7 +43,7 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def show
|
||||
@demande_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.demande_seen_at
|
||||
@demande_seen_at = current_instructeur.follows.find_by(dossier: dossier_with_champs)&.demande_seen_at
|
||||
|
||||
respond_to do |format|
|
||||
format.pdf do
|
||||
|
@ -254,7 +254,15 @@ module Instructeurs
|
|||
@dossier ||= current_instructeur
|
||||
.dossiers
|
||||
.visible_by_administration
|
||||
.includes(champs: :type_de_champ)
|
||||
.find(params[:dossier_id])
|
||||
end
|
||||
|
||||
def dossier_with_champs
|
||||
@dossier ||= current_instructeur
|
||||
.dossiers
|
||||
.visible_by_administration
|
||||
.with_champs
|
||||
.with_annotations
|
||||
.find(params[:dossier_id])
|
||||
end
|
||||
|
||||
|
@ -270,19 +278,19 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def mark_demande_as_read
|
||||
current_instructeur.mark_tab_as_seen(dossier, :demande)
|
||||
current_instructeur.mark_tab_as_seen(@dossier, :demande)
|
||||
end
|
||||
|
||||
def mark_messagerie_as_read
|
||||
current_instructeur.mark_tab_as_seen(dossier, :messagerie)
|
||||
current_instructeur.mark_tab_as_seen(@dossier, :messagerie)
|
||||
end
|
||||
|
||||
def mark_avis_as_read
|
||||
current_instructeur.mark_tab_as_seen(dossier, :avis)
|
||||
current_instructeur.mark_tab_as_seen(@dossier, :avis)
|
||||
end
|
||||
|
||||
def mark_annotations_privees_as_read
|
||||
current_instructeur.mark_tab_as_seen(dossier, :annotations_privees)
|
||||
current_instructeur.mark_tab_as_seen(@dossier, :annotations_privees)
|
||||
end
|
||||
|
||||
def aasm_error_message(exception, target_state:)
|
||||
|
|
|
@ -261,32 +261,33 @@ class Dossier < ApplicationRecord
|
|||
}
|
||||
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
|
||||
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
|
||||
scope :with_champs, -> { includes(champs: :type_de_champ) }
|
||||
scope :with_champs, -> {
|
||||
includes(champs: [
|
||||
:type_de_champ,
|
||||
:geo_areas,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [:type_de_champ, piece_justificative_file_attachment: :blob]
|
||||
])
|
||||
}
|
||||
scope :with_annotations, -> {
|
||||
includes(champs_private: [
|
||||
:type_de_champ,
|
||||
:geo_areas,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [:type_de_champ, piece_justificative_file_attachment: :blob]
|
||||
])
|
||||
}
|
||||
scope :for_api, -> {
|
||||
includes(commentaires: { piece_jointe_attachment: :blob },
|
||||
champs: [
|
||||
:geo_areas,
|
||||
:etablissement,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
]
|
||||
],
|
||||
champs_private: [
|
||||
:geo_areas,
|
||||
:etablissement,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
]
|
||||
],
|
||||
justificatif_motivation_attachment: :blob,
|
||||
attestation: [],
|
||||
avis: { piece_justificative_file_attachment: :blob },
|
||||
traitement: [],
|
||||
etablissement: [],
|
||||
individual: [],
|
||||
user: [])
|
||||
with_champs
|
||||
.with_annotations
|
||||
.includes(commentaires: { piece_jointe_attachment: :blob },
|
||||
justificatif_motivation_attachment: :blob,
|
||||
attestation: [],
|
||||
avis: { piece_justificative_file_attachment: :blob },
|
||||
traitement: [],
|
||||
etablissement: [],
|
||||
individual: [],
|
||||
user: [])
|
||||
}
|
||||
|
||||
scope :with_notifiable_procedure, -> (opts = { notify_on_closed: false }) do
|
||||
|
@ -1157,7 +1158,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def geo_areas
|
||||
champs.includes(:geo_areas).flat_map(&:geo_areas) + champs_private.includes(:geo_areas).flat_map(&:geo_areas)
|
||||
champs.flat_map(&:geo_areas) + champs_private.flat_map(&:geo_areas)
|
||||
end
|
||||
|
||||
def bounding_box
|
||||
|
|
Loading…
Reference in a new issue