move previously-universal clauses to only where they are needed miker/wip/search-deleted
authorMike Rylander <mrylander@gmail.com>
Fri, 8 Mar 2013 21:00:45 +0000 (16:00 -0500)
committerMike Rylander <mrylander@gmail.com>
Fri, 8 Mar 2013 21:01:16 +0000 (16:01 -0500)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index f87260c..ad1cc3a 100644 (file)
@@ -921,6 +921,17 @@ sub toSQL {
                     LIMIT 1
                 )
             )
+            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
     } else {
         $limit_where .= <<"        SQL";
@@ -938,9 +949,6 @@ sub toSQL {
                     AND pr.peer_record = m.source
                 LIMIT 1
             )
-        SQL
-    }
-    $limit_where .= <<"    SQL";
             OR
             EXISTS(
                 SELECT 1 FROM asset.call_number acn
@@ -952,8 +960,8 @@ sub toSQL {
                 LIMIT 1
             )
         )
-    SQL
-
+        SQL
+    }
     # For single records we want the record id
     # For metarecords we want NULL or the only record ID.
     my $agg_record = 'm.source AS record';