LP#1537812: Patron search can time out on useless conditions user/miker/lp1537812-patron_search_timeout
authorMike Rylander <mrylander@gmail.com>
Mon, 25 Jan 2016 16:11:24 +0000 (11:11 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 25 Jan 2016 16:11:24 +0000 (11:11 -0500)
In some situations, the patron search code will send an empty or NULL patron
group string as part of the search parameters. This is not recognized and
causes long (to the point of timing out) search calls. This can be avoided by
checking for the presence of a search value.

It is not clear where the long-running queries are coming from, though it is
likely either the actual patron search interface or from the duplicate check
performed during patron registration.  Therefore, testing is made particularly
difficult.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm

index e2a4edc..ed605d5 100644 (file)
@@ -664,11 +664,17 @@ sub patron_search {
     # group 2 = phone, ident
     # group 3 = barcode
 
-    my $usr = join ' AND ', map { "evergreen.lowercase(CAST($_ AS text)) ~ ?" } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
-    my @usrv = map { "^" . _clean_regex_chars($$search{$_}{value}) } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
+    my ($usr, @usrv, @usr_key_list, @addr_key_list);
+    for my $k (keys %search) {
+        push @usr_key_list, $k if (''.$$search{$k}{group} eq '0' and $$search{$k}{value});
+        push @addr_key_list, $k if (''.$$search{$k}{group} eq '1' and $$search{$k}{value});
+    }
+            
+    my $usr = join ' AND ', map { "evergreen.lowercase(CAST($_ AS text)) ~ ?" } @usr_key_list;
+    my @usrv = map { "^" . _clean_regex_chars($$search{$_}{value}) } @usr_key_list;
 
-    my $addr = join ' AND ', map { "evergreen.lowercase(CAST($_ AS text)) ~ ?" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
-    my @addrv = map { "^" . _clean_regex_chars($$search{$_}{value}) } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
+    my $addr = join ' AND ', map { "evergreen.lowercase(CAST($_ AS text)) ~ ?" } @addr_key_list;
+    my @addrv = map { "^" . _clean_regex_chars($$search{$_}{value}) } @addr_key_list
 
     my $pv = _clean_regex_chars($$search{phone}{value});
     my $iv = _clean_regex_chars($$search{ident}{value});