From d287eac70682eaaa91acb2b4d5e01632777ee082 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 21 Nov 2024 18:38:28 +0100 Subject: [PATCH] refactor: fix n+1 --- app/models/dossier.rb | 2 +- app/models/traitement.rb | 2 ++ app/services/dossier_projection_service.rb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f41be6147..35531a4b9 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -896,7 +896,7 @@ class Dossier < ApplicationRecord end def previously_termine? - traitements.termine.exists? + traitements.any?(&:termine?) end def remove_titres_identite! diff --git a/app/models/traitement.rb b/app/models/traitement.rb index 0a3929b57..95612dfd6 100644 --- a/app/models/traitement.rb +++ b/app/models/traitement.rb @@ -26,4 +26,6 @@ class Traitement < ApplicationRecord self.browser_supported = BrowserSupport.supported?(browser) end end + + def termine? = state.in?(Dossier::TERMINE) end diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index 616ce055a..cd4e9cea3 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -30,7 +30,7 @@ class DossierProjectionService # - the order of the intermediary query results are unknown # - some values can be missing (if a revision added or removed them) def self.project(dossiers_ids, columns) - dossiers = Dossier.includes(:corrections, :pending_corrections).find(dossiers_ids) + dossiers = Dossier.includes(:corrections, :pending_corrections, :traitements).find(dossiers_ids) fields = columns.map do |c| if c.is_a?(Columns::ChampColumn)