From b0be87b5cb7189280c253dc24b545876c6647813 Mon Sep 17 00:00:00 2001
From: miker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Fri, 16 Jul 2010 02:37:24 +0000
Subject: [PATCH] use a left join instead of -not-exists for anti-join -- much
 faster for large nullable-side sets in this case

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16953 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
index b12e897b40..6a916c079e 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
@@ -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");
-- 
2.11.0