chore(dossier_assignment): avoid n+1 queries
This commit is contained in:
parent
e8e9857dda
commit
04160b5d44
3 changed files with 8 additions and 3 deletions
|
@ -91,7 +91,7 @@ module Instructeurs
|
||||||
@avis_emails = dossier.experts.map(&:email)
|
@avis_emails = dossier.experts.map(&:email)
|
||||||
@invites_emails = dossier.invites.map(&:email)
|
@invites_emails = dossier.invites.map(&:email)
|
||||||
@potential_recipients = dossier.groupe_instructeur.instructeurs.reject { |g| g == current_instructeur }
|
@potential_recipients = dossier.groupe_instructeur.instructeurs.reject { |g| g == current_instructeur }
|
||||||
@manual_assignments = dossier.dossier_assignments.manual
|
@manual_assignments = dossier.dossier_assignments.manual.includes(:groupe_instructeur, :previous_groupe_instructeur)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_to_instructeurs
|
def send_to_instructeurs
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
class DossierAssignment < ApplicationRecord
|
class DossierAssignment < ApplicationRecord
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
|
|
||||||
|
belongs_to :groupe_instructeur, optional: true, inverse_of: :assignments
|
||||||
|
belongs_to :previous_groupe_instructeur, class_name: 'GroupeInstructeur', optional: true, inverse_of: :previous_assignments
|
||||||
|
|
||||||
enum mode: {
|
enum mode: {
|
||||||
auto: 'auto',
|
auto: 'auto',
|
||||||
manual: 'manual'
|
manual: 'manual'
|
||||||
|
@ -22,10 +25,10 @@ class DossierAssignment < ApplicationRecord
|
||||||
scope :manual, -> { where(mode: :manual) }
|
scope :manual, -> { where(mode: :manual) }
|
||||||
|
|
||||||
def groupe_instructeur_label
|
def groupe_instructeur_label
|
||||||
@groupe_instructeur_label ||= GroupeInstructeur.find_by(id: groupe_instructeur_id)&.label || read_attribute(:groupe_instructeur_label)
|
@groupe_instructeur_label ||= groupe_instructeur&.label.presence || read_attribute(:groupe_instructeur_label)
|
||||||
end
|
end
|
||||||
|
|
||||||
def previous_groupe_instructeur_label
|
def previous_groupe_instructeur_label
|
||||||
@previous_groupe_instructeur_label ||= GroupeInstructeur.find_by(id: previous_groupe_instructeur_id)&.label || read_attribute(:previous_groupe_instructeur_label)
|
@previous_groupe_instructeur_label ||= previous_groupe_instructeur&.label.presence || read_attribute(:previous_groupe_instructeur_label)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,8 @@ class GroupeInstructeur < ApplicationRecord
|
||||||
has_many :dossiers
|
has_many :dossiers
|
||||||
has_many :deleted_dossiers
|
has_many :deleted_dossiers
|
||||||
has_many :batch_operations, through: :dossiers, source: :batch_operations
|
has_many :batch_operations, through: :dossiers, source: :batch_operations
|
||||||
|
has_many :assignments, class_name: 'DossierAssignment', dependent: :nullify, inverse_of: :groupe_instructeur
|
||||||
|
has_many :previous_assignments, class_name: 'DossierAssignment', dependent: :nullify, inverse_of: :previous_groupe_instructeur
|
||||||
has_and_belongs_to_many :exports, dependent: :destroy
|
has_and_belongs_to_many :exports, dependent: :destroy
|
||||||
has_and_belongs_to_many :bulk_messages, dependent: :destroy
|
has_and_belongs_to_many :bulk_messages, dependent: :destroy
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue