perf(dossier.pdf): use DossierPreloader to generate pdf
This commit is contained in:
parent
07acc0db94
commit
8532c71036
3 changed files with 18 additions and 19 deletions
|
@ -113,24 +113,16 @@ class PiecesJustificativesService
|
|||
pdfs = []
|
||||
|
||||
procedure = dossiers.first.procedure
|
||||
tdc_by_id = TypeDeChamp
|
||||
.joins(:revisions)
|
||||
.where(revisions: { id: procedure.revisions })
|
||||
.to_a
|
||||
.index_by(&:id)
|
||||
dossiers = dossiers.includes(:individual, :traitement, :etablissement, user: :france_connect_information, avis: :expert, commentaires: [:instructeur, :expert])
|
||||
dossiers = DossierPreloader.new(dossiers).in_batches
|
||||
dossiers.each do |dossier|
|
||||
dossier.association(:procedure).target = procedure
|
||||
|
||||
dossiers
|
||||
.includes(:champs, :champs_private, :commentaires, :individual,
|
||||
:traitement, :etablissement,
|
||||
user: :france_connect_information, avis: :expert)
|
||||
.find_each do |dossier|
|
||||
pdf = ApplicationController
|
||||
.render(template: 'dossiers/show', formats: [:pdf],
|
||||
assigns: {
|
||||
include_infos_administration: true,
|
||||
dossier: dossier,
|
||||
procedure: procedure,
|
||||
tdc_by_id: tdc_by_id
|
||||
dossier: dossier
|
||||
})
|
||||
|
||||
a = FakeAttachment.new(
|
||||
|
|
|
@ -130,7 +130,7 @@ def add_identite_etablissement(pdf, etablissement)
|
|||
end
|
||||
|
||||
def add_single_champ(pdf, champ)
|
||||
tdc = @tdc_by_id[champ.type_de_champ_id]
|
||||
tdc = champ.type_de_champ
|
||||
|
||||
case champ.type
|
||||
when 'Champs::PieceJustificativeChamp', 'Champs::TitreIdentiteChamp'
|
||||
|
@ -207,9 +207,6 @@ def add_etats_dossier(pdf, dossier)
|
|||
end
|
||||
|
||||
prawn_document(page_size: "A4") do |pdf|
|
||||
@procedure ||= @dossier.procedure
|
||||
@tdc_by_id ||= @dossier.revision.types_de_champ.index_by(&:id)
|
||||
|
||||
pdf.font_families.update( 'marianne' => {
|
||||
normal: Rails.root.join('lib/prawn/fonts/marianne/marianne-regular.ttf' ),
|
||||
bold: Rails.root.join('lib/prawn/fonts/marianne/marianne-bold.ttf' ),
|
||||
|
@ -221,8 +218,8 @@ prawn_document(page_size: "A4") do |pdf|
|
|||
end
|
||||
|
||||
format_in_2_columns(pdf, 'Dossier Nº', @dossier.id.to_s)
|
||||
format_in_2_columns(pdf, 'Démarche', @procedure.libelle)
|
||||
format_in_2_columns(pdf, 'Organisme', @procedure.organisation_name)
|
||||
format_in_2_columns(pdf, 'Démarche', @dossier.procedure.libelle)
|
||||
format_in_2_columns(pdf, 'Organisme', @dossier.procedure.organisation_name)
|
||||
|
||||
add_etat_dossier(pdf, @dossier)
|
||||
|
||||
|
|
|
@ -18,4 +18,14 @@ namespace :benchmarks do
|
|||
x.report("Démarche 55824") { SerializerService.dossiers(p_55824) }
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Benchmark pdf'
|
||||
task pdf: :environment do
|
||||
p_45964 = Procedure.find(45964)
|
||||
p_55824 = Procedure.find(55824)
|
||||
Benchmark.bm do |x|
|
||||
x.report("Démarche 45964") { PiecesJustificativesService.generate_dossier_export(p_45964.dossiers) }
|
||||
x.report("Démarche 55824") { PiecesJustificativesService.generate_dossier_export(p_55824.dossiers.limit(10_000)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue