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