QueryParser: Adjust visibility order
authorThomas Berezansky <tsbere@mvlc.org>
Tue, 19 Feb 2013 16:39:40 +0000 (11:39 -0500)
committerBen Shum <bshum@biblio.org>
Mon, 25 Feb 2013 16:40:21 +0000 (11:40 -0500)
Checking call number URIs last gives us a faster return on average based on
finding copy information first.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 6e80ba4..ff33c23 100644 (file)
@@ -866,16 +866,6 @@ sub toSQL {
         AND (
             cbs.transcendant IS TRUE
             OR
-            EXISTS(
-                SELECT 1 FROM asset.call_number acn
-                    JOIN asset.uri_call_number_map aucnm ON acn.id = aucnm.call_number
-                    JOIN asset.uri uri ON aucnm.uri = uri.id
-                WHERE NOT acn.deleted AND uri.active AND acn.record = m.source AND acn.owning_lib IN (
-                    SELECT * FROM luri_org_list
-                )
-                LIMIT 1
-            )
-            OR
     SQL
     if ($self->find_modifier('staff')) {
         $limit_where .= <<"        SQL";
@@ -933,7 +923,19 @@ sub toSQL {
             )
         SQL
     }
-    $limit_where .= "        )";
+    $limit_where .= <<"    SQL";
+            OR
+            EXISTS(
+                SELECT 1 FROM asset.call_number acn
+                    JOIN asset.uri_call_number_map aucnm ON acn.id = aucnm.call_number
+                    JOIN asset.uri uri ON aucnm.uri = uri.id
+                WHERE NOT acn.deleted AND uri.active AND acn.record = m.source AND acn.owning_lib IN (
+                    SELECT * FROM luri_org_list
+                )
+                LIMIT 1
+            )
+        )
+    SQL
 
     # For single records we want the record id
     # For metarecords we want NULL or the only record ID.