webstaff: improve performance of open-ils.search.authority.simple_heading.from_xml
authorGalen Charlton <gmc@esilibrary.com>
Thu, 3 Sep 2015 21:13:27 +0000 (21:13 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:19 +0000 (15:44 -0400)
Searching authority.record_entry by comparing are.simple_heading
with the results of authority.simple_normalize_heading() can result
in bad query plans; if we calculate the results of that function
first, we have a much better chance of hitting the index on
simple_heading.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Authority.pm

index d1f42d7..a20dfb1 100644 (file)
@@ -66,19 +66,26 @@ sub search_authority_by_simple_normalize_heading {
     my $marcxml = shift;
     my $controlset = shift;
 
+    my $norm_heading_query = {
+        from => [ 'authority.simple_normalize_heading' => $marcxml ]
+    };
+
+    my $e = new_editor();
+    my $norm_heading = $e->json_query($norm_heading_query)->[0]->{'authority.simple_normalize_heading'};
+
     my $query = {
         select => { are => ['id'] },
         from   => 'are',
         where  => {
             deleted => 'f',
             simple_heading => {
-                'startwith' => [ 'authority.simple_normalize_heading' => $marcxml ]
+                'startwith' => $norm_heading
             },
             defined($controlset) ? ( control_set => $controlset ) : ()
         }
     };
 
-    $client->respond($_->{id}) for @{ new_editor()->json_query( $query ) };
+    $client->respond($_->{id}) for @{ $e->json_query( $query ) };
     $client->respond_complete;
 }
 __PACKAGE__->register_method(