From 47481632315afd4d61482f5fba02c92b003e1256 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 16 May 2006 16:47:09 +0000 Subject: [PATCH] - Added a 2.7% speed increase by precaching i18n messages. This should also help increase shared memory amongst Apache children. (Matt Wilson) --- docs/changelog/6.x.x.txt | 4 ++++ lib/WebGUI/International.pm | 10 +++++----- sbin/preload.perl | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index fb428dfa0..a0b0e969d 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -17,9 +17,13 @@ - fix [ 1486788 ] karma isn't working on forums - fix [ 1489094 ] DataForm Record edit link wrong for list mode (Michelle LaMar) - fix [ 1488663 ] Add new subscription broken (Martin Kamerbeek / Procolix) + - Added a 2.7% speed increase by precaching i18n messages. This should also + help increase shared memory amongst Apache children. (Matt Wilson) - fix [ 1488921 ] Help: Commerce, Manage 6.99.0 + - Added an Events Management System asset that can help people run + conferences, conventions, and large meetings. - Added a workflow system. - Added a workflow scheduler system. - Converted the runHourly.pl scripts to run as scheduled workflows. diff --git a/lib/WebGUI/International.pm b/lib/WebGUI/International.pm index 616ddc632..8ee0ba9b3 100644 --- a/lib/WebGUI/International.pm +++ b/lib/WebGUI/International.pm @@ -17,7 +17,7 @@ package WebGUI::International; use strict qw(vars subs); -our %l10nCache; +our %i18nCache; =head1 NAME @@ -95,7 +95,7 @@ sub get { $id =~ s/$safeRe//g; $language =~ s/$safeRe//g; $namespace =~ s/$safeRe//g; - return $l10nCache{$language}{$namespace}{$id} if $l10nCache{$language}{$namespace}{$id}; + return $i18nCache{$language}{$namespace}{$id}{message} if $i18nCache{$language}{$namespace}{$id}{message}; my $cmd = "WebGUI::i18n::".$language."::".$namespace; my $load = "use ".$cmd; eval($load); @@ -104,7 +104,7 @@ sub get { my $output = eval($cmd); $self->session->errorHandler->warn("Couldn't get value from ".$cmd." because ".$@) if ($@); $output = $self->get($id,$namespace,"English") if ($output eq "" && $language ne "English"); - $l10nCache{$language}{$namespace}{$id} = $output; + $i18nCache{$language}{$namespace}{$id}{message} = $output; return $output; } @@ -225,13 +225,13 @@ Specify a default language. Defaults to user preference or "English". sub new { my ($class, $session, $namespace, $language) = @_; - return $l10nCache{namespaces}{$namespace} if $l10nCache{namespaces}{$namespace}; + return $i18nCache{namespaces}{$namespace} if $i18nCache{namespaces}{$namespace}; my $self = bless( { _session => $session, _namespace => $namespace, _language => ($language || $session->user->profileField('language')), },$class); - $l10nCache{namespaces}{$namespace} = $self; + $i18nCache{namespaces}{$namespace} = $self; return $self; } diff --git a/sbin/preload.perl b/sbin/preload.perl index d1b2c1c22..cc83a7e3f 100644 --- a/sbin/preload.perl +++ b/sbin/preload.perl @@ -55,6 +55,21 @@ use Apache2::ServerUtil (); Apache2::ServerUtil->server->add_version_component("WebGUI/".$WebGUI::VERSION); +#---------------------------------------- +# Precache i18n +#---------------------------------------- +opendir(DIR,$webguiRoot."/lib/WebGUI/i18n/English"); +my @files = readdir(DIR); +closedir(DIR); +foreach my $file (@files) { + if ($file =~ /^(\w+)\.pm$/) { + my $namespace = $1; + my $cmd = "\$WebGUI::i18n::English::".$namespace."::I18N"; + my $data = eval($cmd); + $WebGUI::International::i18nCache{English}{$namespace} = $data; + } +} + #---------------------------------------- # Preload all site configs. #----------------------------------------