From 5708b03000eb649c0feda7d430b0096d1faebade Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 16 Sep 2011 11:49:08 -0400 Subject: [PATCH] Tpac: longer timeout for marc "expert" search Since MARC searches can take a while, raise the default timeout from 1 minute to 2, with the option (at the API layer) of raising it to 5. Signed-off-by: Bill Erickson Signed-off-by: Dan Scott --- .../perlmods/lib/OpenILS/Application/Search/Biblio.pm | 17 ++++++++++++++--- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 12 +++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index 2bc7062eeb..ac8046b3bb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -2161,7 +2161,7 @@ Presently, search uses the cache unconditionally. # FIXME: that example above isn't actually tested. # TODO: docache option? sub marc_search { - my( $self, $conn, $args, $limit, $offset ) = @_; + my( $self, $conn, $args, $limit, $offset, $timeout ) = @_; my $method = 'open-ils.storage.biblio.full_rec.multi_search'; $method .= ".staff" if $self->api_name =~ /staff/; @@ -2170,6 +2170,11 @@ sub marc_search { $limit ||= 10; # FIXME: what about $args->{limit} ? $offset ||= 0; # FIXME: what about $args->{offset} ? + # allow caller to pass in a call timeout since MARC searches + # can take longer than the default 60-second timeout. + # Default to 2 mins. Arbitrarily cap at 5 mins. + $timeout = 120 if !$timeout or $timeout > 300; + my @search; push( @search, ($_ => $$args{$_}) ) for (sort keys %$args); my $ckey = $pfx . md5_hex($method . OpenSRF::Utils::JSON->perl2JSON(\@search)); @@ -2177,13 +2182,19 @@ sub marc_search { my $recs = search_cache($ckey, $offset, $limit); if(!$recs) { - $recs = $U->storagereq($method, %$args) || []; - if( $recs ) { + + my $ses = OpenSRF::AppSession->create('open-ils.storage'); + my $req = $ses->request($method, %$args); + my $resp = $req->recv($timeout); + + if($resp and $recs = $resp->content) { put_cache($ckey, scalar(@$recs), $recs); $recs = [ @$recs[$offset..($offset + ($limit - 1))] ]; } else { $recs = []; } + + $ses->kill_me; } my $count = 0; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index bed087f2ac..7dc650b44f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -338,10 +338,16 @@ sub marc_expert_search { # nothing to do return Apache2::Const::OK if @$query == 0; - my $results = $U->simplereq( - 'open-ils.search', + my $timeout = 120; + my $ses = OpenSRF::AppSession->create('open-ils.search'); + my $req = $ses->request( 'open-ils.search.biblio.marc', - {searches => $query, org_unit => $org_unit}, $limit, $offset); + {searches => $query, org_unit => $org_unit}, + $limit, $offset, $timeout); + + my $resp = $req->recv($timeout); + my $results = $resp ? $resp->content : undef; + $ses->kill_me; if (defined $U->event_code($results)) { $self->apache->log->warn( -- 2.11.0