use a left join instead of -not-exists for anti-join -- much faster for large nullabl...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Jul 2010 02:37:24 +0000 (02:37 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Jul 2010 02:37:24 +0000 (02:37 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16953 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm

index b12e897..6a916c0 100644 (file)
@@ -453,16 +453,16 @@ sub create_batch_events {
             push @{ $$filter{'-and'} }, $f;
         }
 
-        push @{ $filter->{'-and'} }, {
-            '-not-exists' => {
-                from  => 'atev',
-                where => {
-                    event_def => $def->id,
-                    target    => { '=' => { '+' . $hook_hash{$def->hook}->core_type => $class->Identity } },
-                    ($active ? (state  => 'pending') : ())
-                }
+        my $join = { 'join' => {
+            atev => {
+                field => 'target',
+                fkey => $class->Identity,
+                type => 'left',
+                filter => { event_def => $def->id }
             }
-        };
+        }};
+
+        push @{ $filter->{'-and'} }, { '+atev' => { id => undef } };
 
         if ($def->usr_field && $def->opt_in_setting) {
             push @{ $filter->{'-and'} }, {
@@ -487,7 +487,7 @@ sub create_batch_events {
 
         $logger->info("trigger: create_batch_events() collecting object IDs for def=$def_id / hook=$hook");
 
-        my $object_ids = $editor->$method( $filter, {idlist => 1, timeout => 10800} );
+        my $object_ids = $editor->$method( [$filter, $join], {idlist => 1, timeout => 10800} );
 
         if($object_ids) {
             $logger->info("trigger: create_batch_events() fetched ".scalar(@$object_ids)." object IDs for def=$def_id / hook=$hook");