Commit 774707ad authored by Xavier Guimard's avatar Xavier Guimard

Add cache to avoid parsing and compiling JSON files at each request (#1595)

parent 81c88216
......@@ -17,6 +17,8 @@ use strict;
use URI::Escape;
use JSON;
has trOverCache => ( is => 'rw', default => sub { {} } );
# List constants
sub authProcess { qw(extractFormInfo getUser authenticate) }
......@@ -749,23 +751,26 @@ sub sendHtml {
# Override messages
my $trOverMessages = JSON::from_json( $self->trOver );
opendir( DIR, $templateDir );
my @langfiles = grep( /\.json$/, readdir(DIR) );
close(DIR);
foreach my $file (@langfiles) {
my ($lang) = ( $file =~ /^(\w+)\.json/ );
$self->logger->debug("Use $file to override messages");
if ( open my $json, "<", $templateDir . "/" . $file ) {
local $/ = undef;
$trOverMessages->{$lang} = JSON::from_json(<$json>);
}
else {
$self->logger->error("Unable to read $file");
unless ( $self->trOverCache->{$templateDir} ) {
opendir( DIR, $templateDir );
my @langfiles = grep( /\.json$/, readdir(DIR) );
close(DIR);
foreach my $file (@langfiles) {
my ($lang) = ( $file =~ /^(\w+)\.json/ );
$self->logger->debug("Use $file to override messages");
if ( open my $json, "<", $templateDir . "/" . $file ) {
local $/ = undef;
$trOverMessages->{$lang} = JSON::from_json(<$json>);
}
else {
$self->logger->error("Unable to read $file");
}
}
}
$args{params}->{TROVER} = JSON::to_json($trOverMessages);
$self->trOverCache->{$templateDir} = JSON::to_json($trOverMessages);
}
$args{params}->{TROVER} = $self->trOverCache->{$templateDir};
my $res = $self->SUPER::sendHtml( $req, $template, %args );
push @{ $res->[1] },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment