[open-ils-commits] [GIT] Evergreen ILS branch master updated. 4c8a1b71ebd961ebe2a5dffcb1690ea6fb6b281b

Evergreen Git git at git.evergreen-ils.org
Wed Jun 27 14:02:05 EDT 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  4c8a1b71ebd961ebe2a5dffcb1690ea6fb6b281b (commit)
      from  68a4e3b1c8133c9c98503f5d2128e054bf1d2114 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4c8a1b71ebd961ebe2a5dffcb1690ea6fb6b281b
Author: Mike Rylander <mrylander at gmail.com>
Date:   Tue Jun 26 15:03:37 2012 -0400

    Teach the autosuggest web service to cache suggestions where appropriate
    
    Should spare some DB load on sites.
    
    LFW: I'm not sure the update to the Apache config made any difference,
    but it doesn't hurt.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/examples/apache/eg.conf b/Open-ILS/examples/apache/eg.conf
index e2b0584..280cea6 100644
--- a/Open-ILS/examples/apache/eg.conf
+++ b/Open-ILS/examples/apache/eg.conf
@@ -19,6 +19,7 @@ PerlChildInitHandler OpenILS::WWW::Reporter::child_init
 PerlChildInitHandler OpenILS::WWW::SuperCat::child_init
 PerlChildInitHandler OpenILS::WWW::AddedContent::child_init
 PerlChildInitHandler OpenILS::WWW::PasswordReset::child_init
+PerlChildInitHandler OpenILS::WWW::AutoSuggest::child_init
 
 # ----------------------------------------------------------------------------------
 # Set some defaults for our working directories
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm
index 7ed9bf7..c0a9246 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm
@@ -10,9 +10,32 @@ use Apache2::Const -compile => qw(
 use XML::LibXML;
 use Text::Glob;
 use CGI qw(:all -utf8);
+use Digest::MD5 qw(md5_hex);
 
 use OpenSRF::Utils::JSON;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
+use OpenSRF::Utils::Logger qw/:level/;
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Cache;
+
+my $log = 'OpenSRF::Utils::Logger';
+
+my $init_done = 0;
+my $cache;
+my $cache_timeout;
+
+sub initialize {
+
+    my $conf = OpenSRF::Utils::SettingsClient->new;
+
+    $cache_timeout = $conf->config_value(
+            "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
+
+}
+sub child_init {
+    $cache = OpenSRF::Utils::Cache->new('global');
+    $init_done = 1;
+}
 
 # BEGIN package globals
 
@@ -91,7 +114,23 @@ sub get_suggestions {
         defined $short_word_length ? int($short_word_length) : undef
     );
 
-    return $editor->json_query({
+    my $key = 'oils_AS_' . md5_hex(
+        $query .
+        $search_class .
+        $org_unit .
+        $css_prefix .
+        $highlight_min .
+        $highlight_max .
+        $normalization .
+        $limit .
+        $short_word_length
+    );
+
+    my $res = $cache->get_cache( $key );
+
+    return $res if ($res);
+
+    $res = $editor->json_query({
         "from" => [
             "metabib.suggest_browse_entries",
             $query,
@@ -102,6 +141,10 @@ sub get_suggestions {
             $normalization
         ]
     });
+
+    $cache->put_cache( $key => $res => $cache_timeout );
+
+    return $res;
 }
 
 sub suggestions_to_xml {
@@ -160,6 +203,8 @@ sub output_handler {
 }
 
 sub handler {
+    child_init() unless $init_done;
+
     my $r = shift;
     my $cgi = new CGI;
 

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/apache/eg.conf                   |    1 +
 .../src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm    |   47 +++++++++++++++++++-
 2 files changed, 47 insertions(+), 1 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list