perf(tags parser): improuve parser perf
This commit is contained in:
parent
d82620d1ff
commit
626b28ca16
2 changed files with 6 additions and 25 deletions
|
@ -41,11 +41,11 @@ module TagsSubstitutionConcern
|
|||
end
|
||||
|
||||
define_combinator :tag_text_first_char do
|
||||
any_char.that_fail(lit('-') | tag_delimiter | eol)
|
||||
any_char.that_fail(lit('-') | tag_delimiter)
|
||||
end
|
||||
|
||||
define_combinator :tag_text_char do
|
||||
any_char.that_fail(tag_delimiter | eol)
|
||||
any_char.that_fail(tag_delimiter)
|
||||
end
|
||||
|
||||
define_combinator :tag_text do
|
||||
|
@ -53,10 +53,6 @@ module TagsSubstitutionConcern
|
|||
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
|
||||
end
|
||||
end
|
||||
|
||||
define_combinator :eol do
|
||||
lit("\r\n") | lit("\n")
|
||||
end
|
||||
end
|
||||
|
||||
DOSSIER_TAGS = [
|
||||
|
|
|
@ -32,25 +32,10 @@ namespace :benchmarks do
|
|||
|
||||
desc 'Attestation Template parser'
|
||||
task attestation_template_parser: :environment do
|
||||
progress = ProgressReport.new(AttestationTemplate.count)
|
||||
AttestationTemplate.find_each do |template|
|
||||
parsed = TagsSubstitutionConcern::TagsParser.parse(template.body)
|
||||
serialized = parsed.map do |token|
|
||||
case token
|
||||
in { tag: tag }
|
||||
"--#{tag}--"
|
||||
in { text: text }
|
||||
text
|
||||
end
|
||||
end.join('')
|
||||
if serialized != template.body
|
||||
throw "Template '#{serialized}' is not eq '#{template.body}' with attestation template #{template.id}"
|
||||
end
|
||||
progress.inc
|
||||
rescue => e
|
||||
pp "Error with attestation template #{template.id}"
|
||||
throw e
|
||||
procedure = Procedure.find(68139)
|
||||
Benchmark.bm do |x|
|
||||
x.report("Empty") { TagsSubstitutionConcern::TagsParser.parse('') }
|
||||
x.report("Démarche 68139") { TagsSubstitutionConcern::TagsParser.parse(procedure.attestation_template.body) }
|
||||
end
|
||||
progress.finish
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue