From 0c3282756a4b842702162c35ba4b52f35cc119a4 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 30 Aug 2006 02:35:48 +0000 Subject: [PATCH] added caching version of batch call git-svn-id: svn://svn.open-ils.org/ILS/trunk@5766 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Search/Authority.pm | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm index b8c9b2ce1c..3514172850 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm @@ -15,6 +15,9 @@ use Time::HiRes qw(time); use OpenSRF::EX qw(:try); use Digest::MD5 qw(md5_hex); +my $cache; + + sub validate_authority { my $self = shift; my $client = shift; @@ -121,7 +124,8 @@ __PACKAGE__->register_method( ); __PACKAGE__->register_method( - method => "new_crossref_authority_batch", + #method => "new_crossref_authority_batch", + method => "crossref_authority_batch2", api_name => "open-ils.search.authority.crossref.batch", argc => 1, note => <<" NOTE"); @@ -212,6 +216,55 @@ sub crossref_authority_batch { +sub crossref_authority_batch2 { + my( $self, $client, $reqs ) = @_; + + my $response = {}; + my $lastr = []; + my $session = OpenSRF::AppSession->create("open-ils.storage"); + + $cache = OpenSRF::Utils::Cache->new('global') unless $cache; + + for my $req (@$reqs) { + + my $class = $req->[0]; + my $term = $req->[1]; + next unless $class and $term; + + my $t = $term; + $t =~ s/\s//og; + my $cdata = $cache->get_cache("oils_authority_${class}_$t"); + + if( $cdata ) { + $logger->debug("returning authority response from cache.."); + $response->{$class} = {} unless exists $response->{$class}; + $response->{$class}->{$term} = $cdata; + next; + } + + $logger->debug("authority data not found in cache.. fetching from storage"); + + warn "Sending authority request for $class : $term\n"; + my $freq = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term, 10); + my $areq = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term, 10); + my $fr = $freq->gather(1); + my $al = $areq->gather(1); + $response->{$class} = {} unless exists $response->{$class}; + my $auth = _auth_flatten( $term, $fr, $al, 1 ); + + my $timeout = 7200; #two hours + $timeout = 300 if @{$auth->{from}} or @{$auth->{also}}; # 5 minutes + $response->{$class}->{$term} = $auth; + $logger->debug("adding authority lookup to cache with timeout $timeout"); + $cache->put_cache("oils_authority_${class}_$t", $auth, $timeout); + } + return $response; +} + + + + + __PACKAGE__->register_method( method => "authority_to_html", api_name => "open-ils.search.authority.to_html" ); @@ -224,6 +277,7 @@ my $stylesheet; sub authority_to_html { my( $self, $client, $id ) = @_; + if( !$stylesheet ) { my $sclient = OpenSRF::Utils::SettingsClient->new(); my $dir = $sclient->config_value( "dirs", "xsl" ); -- 2.43.2