LP1825851 Default to no template caching
authorBill Erickson <berickxx@gmail.com>
Mon, 22 Apr 2019 15:17:50 +0000 (08:17 -0700)
committerBill Erickson <berickxx@gmail.com>
Wed, 10 Jul 2019 20:04:26 +0000 (16:04 -0400)
To enable template cacheing, passing a true value as the second import
argument for PrintTemplate in eg_startup.pl

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/apache_24/eg_startup.in
Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm

index 316034a..72e2903 100755 (executable)
@@ -15,7 +15,7 @@ use OpenILS::WWW::IDL2js ('@sysconfdir@/opensrf_core.xml');
 use OpenILS::WWW::FlatFielder;
 use OpenILS::WWW::PhoneList ('@sysconfdir@/opensrf_core.xml');
 
-# Pass second argument of '1' to disable template caching.                     
+# Pass second argument of '1' to enable template caching.                     
 use OpenILS::WWW::PrintTemplate ('/openils/conf/opensrf_core.xml', 0);  
 
 # - Uncomment the following 2 lines to make use of the IP redirection code
index bd9f52b..2c33f78 100644 (file)
@@ -4,7 +4,11 @@ use Apache2::Const -compile =>
     qw(OK FORBIDDEN NOT_FOUND HTTP_INTERNAL_SERVER_ERROR HTTP_BAD_REQUEST);
 use Apache2::RequestRec;
 use CGI;
-use HTML::Restrict;
+# Requires a new CPAN module.  
+# Leaving commented for now to ease testing, pending agreement on the 
+# approach for html srubbing.
+# $ sudo cpan HTML::Restrict
+#use HTML::Restrict;
 use OpenSRF::Utils::JSON;
 use OpenSRF::System;
 use OpenSRF::Utils::SettingsClient;
@@ -14,10 +18,10 @@ use OpenILS::Application::AppUtils;
 my $U = 'OpenILS::Application::AppUtils';
 
 my $bs_config;
-my $disable_cache;
+my $enable_cache; # Enable process-level template caching
 sub import {
     $bs_config = shift;
-    $disable_cache = shift;
+    $enable_cache = shift;
 }
 
 my $init_complete = 0;
@@ -25,7 +29,7 @@ sub child_init {
     $init_complete = 1;
 
     OpenSRF::System->bootstrap_client(config_file => $bs_config);
-    OpenILS::Utils::CStoreEditor->init; # just in case
+    OpenILS::Utils::CStoreEditor->init;
     return Apache2::Const::OK;
 }
 
@@ -56,7 +60,9 @@ my $rules = {
     u       => [qw(class style)],
     ul      => [qw(class style)],
 };
-my $hr = HTML::Restrict->new(rules => $rules);
+
+my $hr;
+#my $hr = HTML::Restrict->new(rules => $rules);
 
 sub handler {
     my $r = shift;
@@ -103,9 +109,8 @@ sub handler {
 
     if ($stat) { # OK
         my $ctype = $template->content_type;
-        if ($ctype eq 'text/html') {
-            # Scrub the HTML
-            $output = $hr->process($output);
+        if ($hr && $ctype eq 'text/html') {
+            $output = $hr->process($output); # Scrub the HTML
         }
         # TODO
         # client current expects content type to only contain type.
@@ -134,12 +139,13 @@ sub find_template {
     }
 
     return  $template_cache{$owner}{$name}{$locale}
-        if  $template_cache{$owner} && 
+        if  $enable_cache &&
+            $template_cache{$owner} && 
             $template_cache{$owner}{$name} &&
             $template_cache{$owner}{$name}{$locale};
 
     while ($owner) {
-        my ($org) = $U->fetch_org_unit($owner); # internally cached
+        my ($org) = $U->fetch_org_unit($owner); # cached in AppUtils
         
         my $template = $e->search_config_print_template({
             name => $name, 
@@ -149,7 +155,8 @@ sub find_template {
         })->[0];
 
         if ($template) {
-            if (!$disable_cache) {
+
+            if ($enable_cache) {
                 $template_cache{$owner} = {} unless $template_cache{$owner};
                 $template_cache{$owner}{$name} = {} 
                     unless $template_cache{$owner}{$name};