From 984ea80e7c8b331591a256369faabeea0a6acd89 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 5 May 2015 22:15:39 +0000 Subject: [PATCH] LP#1452366: allow EGWeb context loaders to have child_init actions This patch adds the ability for EGWeb to call an initialization function for context loaders during the child_init phase of Apache backend startup. In particular, portions of the R/O object cache for EGCatLoader are now initialized when a backend starts up; testing indicates that this can shave a couple seconds off the time it takes for a backend to render a bib details page the first time. Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander Signed-off-by: Bill Erickson --- Open-ILS/examples/apache/eg_startup.in | 2 +- Open-ILS/examples/apache_24/eg.conf.in | 1 + .../lib/OpenILS/WWW/EGCatLoader/Util.pm | 25 +++++++++++++++++++ .../src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 24 ++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Open-ILS/examples/apache/eg_startup.in b/Open-ILS/examples/apache/eg_startup.in index 1d77c0529b..855159e16f 100755 --- a/Open-ILS/examples/apache/eg_startup.in +++ b/Open-ILS/examples/apache/eg_startup.in @@ -10,7 +10,7 @@ use OpenILS::WWW::AddedContent qw( @sysconfdir@/opensrf_core.xml ); use OpenILS::WWW::Proxy ('@sysconfdir@/opensrf_core.xml'); use OpenILS::WWW::Vandelay qw( @sysconfdir@/opensrf_core.xml ); use OpenILS::WWW::TemplateBatchBibUpdate qw( @sysconfdir@/opensrf_core.xml ); -use OpenILS::WWW::EGWeb; +use OpenILS::WWW::EGWeb ('@sysconfdir@/opensrf_core.xml', 'OpenILS::WWW::EGCatLoader', 'en_us');; use OpenILS::WWW::IDL2js ('@sysconfdir@/opensrf_core.xml'); use OpenILS::WWW::FlatFielder; use OpenILS::WWW::PhoneList ('@sysconfdir@/opensrf_core.xml'); diff --git a/Open-ILS/examples/apache_24/eg.conf.in b/Open-ILS/examples/apache_24/eg.conf.in index b33581d1c5..33f7d03268 100644 --- a/Open-ILS/examples/apache_24/eg.conf.in +++ b/Open-ILS/examples/apache_24/eg.conf.in @@ -20,6 +20,7 @@ PerlChildInitHandler OpenILS::WWW::SuperCat::child_init PerlChildInitHandler OpenILS::WWW::AddedContent::child_init PerlChildInitHandler OpenILS::WWW::AutoSuggest::child_init PerlChildInitHandler OpenILS::WWW::PhoneList::child_init +PerlChildInitHandler OpenILS::WWW::EGWeb::child_init # ---------------------------------------------------------------------------------- # Set some defaults for our working directories diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 43f4a37582..69bb8986be 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -25,6 +25,31 @@ our %cache = ( # cached data authority_fields => {en_us => {}} ); +sub child_init { + my $class = shift; + my %locales = @_; + + # create a stub object with just enough in place + # to call init_ro_object_cache() + my $stub = bless({}, ref($class) || $class); + my $ctx = {}; + $stub->ctx($ctx); + + foreach my $locale (sort keys %locales) { + OpenSRF::AppSession->default_locale($locales{$locale}); + $ctx->{locale} = $locale; + $stub->init_ro_object_cache(); + + # pre-cache various sets of objects + # known to be time-consuming to retrieve + # the first go around + $ro_object_subs->{$locale}->{aou_tree}(); + $ro_object_subs->{$locale}->{aouct_tree}(); + $ro_object_subs->{$locale}->{ccvm_list}(); + $ro_object_subs->{$locale}->{get_authority_fields}(1); + } +} + sub init_ro_object_cache { my $self = shift; my $ctx = $self->ctx; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 8b3fcbfb73..f2f6f40033 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -25,6 +25,30 @@ my %vhost_path_cache; # cache template processors by vhost my %vhost_processor_cache; +my $bootstrap_config; +my @context_loaders_to_preinit = (); +my %locales_to_preinit = (); + +sub import { + my ($self, $bootstrap_config, $loaders, $locales) = @_; + @context_loaders_to_preinit = split /\s+/, $loaders, -1 if defined($loaders); + %locales_to_preinit = map { $_ => parse_eg_locale($_) } + split /\s+/, $locales, -1 if defined($locales); +} + +sub child_init { + OpenSRF::System->bootstrap_client(config_file => $bootstrap_config); + my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL"); + Fieldmapper->import(IDL => $idl); + foreach my $loader (@context_loaders_to_preinit) { + eval { + $loader->use; + $loader->child_init(%locales_to_preinit); + }; + } + return Apache2::Const::OK; +} + sub handler { my $r = shift; my $stat = handler_guts($r); -- 2.43.2