[open-ils-commits] r17631 - in branches/rel_2_0/Open-ILS: src/perlmods/OpenILS/Application web/js/dojo/openils web/js/dojo/openils/widget (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Sep 13 11:55:24 EDT 2010


Author: miker
Date: 2010-09-13 11:55:21 -0400 (Mon, 13 Sep 2010)
New Revision: 17631

Modified:
   branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm
   branches/rel_2_0/Open-ILS/web/js/dojo/openils/I18N.js
   branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/Searcher.js
Log:
Backport r17629 and r17630 from trunk: teach fielder to cache (off by default), with a default timeout of 5min; have fielder cache some frequently used data

Modified: branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm
===================================================================
--- branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm	2010-09-13 15:48:41 UTC (rev 17630)
+++ branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm	2010-09-13 15:55:21 UTC (rev 17631)
@@ -9,6 +9,7 @@
 
 use OpenSRF::AppSession;
 use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Cache;
 use OpenSRF::Utils::Logger qw/:level/;
 
 use OpenILS::Utils::Fieldmapper;
@@ -16,6 +17,8 @@
 
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 
+use Digest::MD5 qw(md5_hex);
+
 use XML::LibXML;
 use XML::LibXML::XPathContext;
 use XML::LibXSLT;
@@ -31,6 +34,8 @@
 
 my $log = 'OpenSRF::Utils::Logger';
 
+my $cache;
+my $cache_timeout;
 my $parser = XML::LibXML->new();
 my $xslt = XML::LibXSLT->new();
 
@@ -48,10 +53,15 @@
 
     $log->debug( 'IDL XML file loaded' );
 
+    $cache_timeout = $conf->config_value(
+            "apps", "open-ils.fielder", "app_settings", "cache_timeout" ) || 300;
+
     generate_methods();
 
 }
-sub child_init {}
+sub child_init {
+    $cache = OpenSRF::Utils::Cache->new('global');
+}
 
 sub fielder_fetch {
     my $self = shift;
@@ -59,9 +69,12 @@
     my $obj = shift;
 
     my $query = $obj->{query};
+    my $nocache = $obj->{cache} ? 0 : 1;
     my $fields = $obj->{fields};
     my $distinct = $obj->{distinct} ? 1 : 0;
 
+    return undef unless $query;
+
     my $obj_class = $self->{class_hint};
     my $fm_class = $self->{class_name};
 
@@ -69,18 +82,34 @@
         $fields = [ $fm_class->real_fields ];
     }
 
-    $log->debug( 'Field list: '. OpenSRF::Utils::JSON->perl2JSON( $fields ) );
-    $log->debug( 'Query: '. OpenSRF::Utils::JSON->perl2JSON( $query ) );
-
-    return undef unless $fields;
-    return undef unless $query;
-
     $fields = [$fields] if (!ref($fields));
 
+    my $qstring = OpenSRF::Utils::JSON->perl2JSON( $query );
+    my $fstring = OpenSRF::Utils::JSON->perl2JSON( [ sort { $a cmp $b } @$fields ] );
 
     $log->debug( 'Query Class: '. $obj_class );
+    $log->debug( 'Field list: '. $fstring );
+    $log->debug( 'Query: '. $qstring );
 
-    my $res = new_editor()->json_query({
+    my ($key,$res);
+    unless ($nocache) {
+        $key = 'open-ils.fielder_' . md5_hex(
+            $self->api_name . 
+            $qstring .
+            $fstring .
+            $distinct .
+            $obj_class
+        );
+
+        $res = $cache->get_cache( $key );
+
+        if ($res) {
+            $client->respond($_) for (@$res);
+            return undef;
+        }
+    }
+
+    $res = new_editor()->json_query({
         select  => { $obj_class => $fields },
         from    => $obj_class,
         where   => $query,
@@ -91,8 +120,10 @@
         $client->respond($value);
     }
 
+    $client->respond_complete();
+
+    $cache->put_cache( $key => $res => $cache_timeout ) unless ($nocache);
     return undef;
-
 }
 
 sub generate_methods {

Modified: branches/rel_2_0/Open-ILS/web/js/dojo/openils/I18N.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/I18N.js	2010-09-13 15:48:41 UTC (rev 17630)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/I18N.js	2010-09-13 15:55:21 UTC (rev 17631)
@@ -25,7 +25,7 @@
 
     dojo.declare('openils.I18N', null, {});
 
-	openils.I18N.BaseLocales = fieldmapper.standardRequest( [ 'open-ils.fielder', 'open-ils.fielder.i18n_l.atomic'], [ { query : { code : { '!=' :  null }  } } ] );
+	openils.I18N.BaseLocales = fieldmapper.standardRequest( [ 'open-ils.fielder', 'open-ils.fielder.i18n_l.atomic'], [ { cache : 1, query : { code : { '!=' :  null }  } } ] );
 	openils.I18N.localeStore = new dojo.data.ItemFileWriteStore( { data : {identifier : 'locale', label : 'label', items : [] } } );
 	openils.I18N.BaseLocales = openils.I18N.BaseLocales.sort(
         function(a, b) {

Modified: branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/Searcher.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/Searcher.js	2010-09-13 15:48:41 UTC (rev 17630)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/Searcher.js	2010-09-13 15:55:21 UTC (rev 17631)
@@ -274,7 +274,7 @@
 
             var fielder_result = fieldmapper.standardRequest(
                 [ 'open-ils.fielder', 'open-ils.fielder.'+c.classname+'.atomic'],
-                [ { query : q } ]
+                [ { cache : 1, query : q } ]
             );
 
             var sorted_fielder_result = fielder_result.sort( function(a,b) {



More information about the open-ils-commits mailing list