LP#1499537 Moved storage of kpac.xml to hash user/ldw/LP1499537_kpac_xml_caching
authorLiam Whalen <liam.whalen@bc.libraries.coop>
Fri, 25 Sep 2015 18:19:43 +0000 (11:19 -0700)
committerLiam Whalen <liam.whalen@bc.libraries.coop>
Fri, 25 Sep 2015 18:27:57 +0000 (11:27 -0700)
In order to increase performance, the check for the cached version of
kpac.xml has been restored and modified to use a global hash rather than
a global scalar.

Signed-off-by: Liam Whalen <liam.whalen@bc.libraries.coop>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm

index 0a0f8dc..260914c 100644 (file)
@@ -7,7 +7,7 @@ use OpenSRF::Utils::Logger qw/$logger/;
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 my $U = 'OpenILS::Application::AppUtils';
-my $kpac_config;
+my %kpac_config;
 
 # -----------------------------------------------------------------------------
 # Override our parent's load() sub so we can do kpac-specific path routing.
@@ -238,29 +238,32 @@ sub load_kpac_config {
         $self->apache->log->error("KPacConfigFile required!");
         return;
     }
+
+    if (!$kpac_config{$path}) {
     
-    $kpac_config = XMLin(
-        $path,
-        KeyAttr => ['id'],
-        ForceArray => ['layout', 'page', 'cell'],
-        NormaliseSpace => 2
-    );
+        $kpac_config{$path} = XMLin(
+            $path,
+            KeyAttr => ['id'],
+            ForceArray => ['layout', 'page', 'cell'],
+            NormaliseSpace => 2
+        );
+    }
 
     my $ou = $ctx->{physical_loc} || $self->_get_search_lib;
     my $layout;
 
     # Search up the org tree to find the nearest config for the context org unit
     while (my $org = $ctx->{get_aou}->($ou)) {
-        ($layout) = grep {$_->{owner} eq $org->id} @{$kpac_config->{layout}};
+        ($layout) = grep {$_->{owner} eq $org->id} @{$kpac_config{$path}->{layout}};
         last if $layout;
         $ou = $org->parent_ou;
     }
 
     $ctx->{kpac_layout} = $layout;
-    $ctx->{kpac_config} = $kpac_config;
+    $ctx->{kpac_config} = $kpac_config{$path};
     $ctx->{kpac_root} = $ctx->{base_path} . "/kpac"; 
     $ctx->{home_page} = $ctx->{proto} . '://' . $ctx->{hostname} . $ctx->{kpac_root} . "/home";
-    $ctx->{global_search_filter} = $kpac_config->{global_filter};
+    $ctx->{global_search_filter} = $kpac_config{$path}->{global_filter};
 }