refactor: fix n+1

This commit is contained in:
simon lehericey 2024-11-21 18:38:28 +01:00
parent 18a4ee450f
commit d287eac706
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 4 additions and 2 deletions

View file

@ -896,7 +896,7 @@ class Dossier < ApplicationRecord
end
def previously_termine?
traitements.termine.exists?
traitements.any?(&:termine?)
end
def remove_titres_identite!

View file

@ -26,4 +26,6 @@ class Traitement < ApplicationRecord
self.browser_supported = BrowserSupport.supported?(browser)
end
end
def termine? = state.in?(Dossier::TERMINE)
end

View file

@ -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)