forcing cache timeout on staged search cacheing (*sigh*). added some logging for...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 21 Aug 2008 13:39:44 +0000 (13:39 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 21 Aug 2008 13:39:44 +0000 (13:39 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10389 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm

index fa5eac4..dfcbcf4 100644 (file)
@@ -154,11 +154,10 @@ sub new_crossref_authority_batch {
                my $class = $req->[0];
                my $term = $req->[1];
                next unless $class and $term;
-               warn "Sending authority request for $class : $term\n";
+               $logger->info("Sending authority request for $class : $term");
                my $fr = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term, 10)->gather(1);
                my $al = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term, 10)->gather(1);
 
-               warn "Flattening $class : $term\n";
                $response->{$class} = {} unless exists $response->{$class};
                $response->{$class}->{$term} = _auth_flatten( $term, $fr, $al, 1 );
 
@@ -180,7 +179,7 @@ sub crossref_authority_batch {
                my $class = $req->[0];
                my $term = $req->[1];
                next unless $class and $term;
-               warn "Sending authority request for $class : $term\n";
+               $logger->info("Sending authority request for $class : $term");
                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);
 
@@ -189,7 +188,6 @@ sub crossref_authority_batch {
                        my $trm = $lastr->[1];
                        my $fr  = $lastr->[2];
                        my $al  = $lastr->[3];
-                       warn "Flattening $class : $term\n";
                        $response->{$cls} = {} unless exists $response->{$cls};
                        $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1 );
                }
@@ -205,7 +203,6 @@ sub crossref_authority_batch {
                my $trm = $lastr->[1];
                my $fr  = $lastr->[2];
                my $al  = $lastr->[3];
-               warn "Flattening $cls : $trm\n";
                $response->{$cls} = {} unless exists $response->{$cls};
                $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1);
        }
@@ -244,7 +241,7 @@ sub crossref_authority_batch2 {
 
                $logger->debug("authority data not found in cache.. fetching from storage");
 
-               warn "Sending authority request for $class : $term\n";
+               $logger->info("Sending authority request for $class : $term");
                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);      
index 09ebf4f..ae40e14 100644 (file)
@@ -764,6 +764,7 @@ sub staged_search {
     $method .= '.staff' if $self->api_name =~ /staff$/;
     $method .= '.atomic';
 
+    my $search_duration;
     my $user_offset = $search_hash->{offset} || 0; # user-specified offset
     my $user_limit = $search_hash->{limit} || 10;
     $user_offset = ($user_offset >= 0) ? $user_offset : 0;
@@ -820,9 +821,23 @@ sub staged_search {
             $search_hash->{skip_check} = $page * $superpage_size;
             my $start = time;
             $results = $U->storagereq($method, %$search_hash);
-            $logger->info("staged search: DB call took ".(time - $start)." seconds");
+            $search_duration = time - $start;
+            $logger->info("staged search: DB call took $search_duration seconds");
             $summary = shift(@$results);
 
+            unless($summary) {
+                $logger->info("search timed out: duration=$search_duration: params=".
+                    OpenSRF::Utils::JSON->perl2JSON($search_hash));
+                return {count => 0};
+            }
+
+            my $hc = $summary->{estimated_hit_count} || $summary->{visible};
+            if($hc == 0) {
+                $logger->info("search returned 0 results: duration=$search_duration: params=".
+                    OpenSRF::Utils::JSON->perl2JSON($search_hash));
+                return {count => 0};
+            }
+
             # Create backwards-compatible result structures
             if($self->api_name =~ /biblio/) {
                 $results = [map {[$_->{id}]} @$results];
@@ -922,7 +937,7 @@ sub cache_staged_search_page {
     $logger->info("staged search: cached with key=$key, superpage=$page, estimated=".
         $summary->{estimated_hit_count}.", visible=".$summary->{visible});
 
-    $cache->put_cache($key, $data);
+    $cache->put_cache($key, $data, $cache_timeout);
 }
 
 sub search_cache {