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
|
end
|
||||||
|
|
||||||
def show
|
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|
|
respond_to do |format|
|
||||||
format.pdf do
|
format.pdf do
|
||||||
|
@ -254,7 +254,15 @@ module Instructeurs
|
||||||
@dossier ||= current_instructeur
|
@dossier ||= current_instructeur
|
||||||
.dossiers
|
.dossiers
|
||||||
.visible_by_administration
|
.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])
|
.find(params[:dossier_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -270,19 +278,19 @@ module Instructeurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_demande_as_read
|
def mark_demande_as_read
|
||||||
current_instructeur.mark_tab_as_seen(dossier, :demande)
|
current_instructeur.mark_tab_as_seen(@dossier, :demande)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_messagerie_as_read
|
def mark_messagerie_as_read
|
||||||
current_instructeur.mark_tab_as_seen(dossier, :messagerie)
|
current_instructeur.mark_tab_as_seen(@dossier, :messagerie)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_avis_as_read
|
def mark_avis_as_read
|
||||||
current_instructeur.mark_tab_as_seen(dossier, :avis)
|
current_instructeur.mark_tab_as_seen(@dossier, :avis)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_annotations_privees_as_read
|
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
|
end
|
||||||
|
|
||||||
def aasm_error_message(exception, target_state:)
|
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 :en_cours, -> { not_archived.state_en_construction_ou_instruction }
|
||||||
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
|
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, -> {
|
scope :for_api, -> {
|
||||||
includes(commentaires: { piece_jointe_attachment: :blob },
|
with_champs
|
||||||
champs: [
|
.with_annotations
|
||||||
:geo_areas,
|
.includes(commentaires: { piece_jointe_attachment: :blob },
|
||||||
:etablissement,
|
justificatif_motivation_attachment: :blob,
|
||||||
piece_justificative_file_attachment: :blob,
|
attestation: [],
|
||||||
champs: [
|
avis: { piece_justificative_file_attachment: :blob },
|
||||||
piece_justificative_file_attachment: :blob
|
traitement: [],
|
||||||
]
|
etablissement: [],
|
||||||
],
|
individual: [],
|
||||||
champs_private: [
|
user: [])
|
||||||
: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: [])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :with_notifiable_procedure, -> (opts = { notify_on_closed: false }) do
|
scope :with_notifiable_procedure, -> (opts = { notify_on_closed: false }) do
|
||||||
|
@ -1157,7 +1158,7 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def geo_areas
|
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
|
end
|
||||||
|
|
||||||
def bounding_box
|
def bounding_box
|
||||||
|
|
Loading…
Add table
Reference in a new issue