Implement a process-local cache for event target fleshing -- particularly helpful...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Oct 2010 19:39:51 +0000 (19:39 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Oct 2010 19:39:51 +0000 (19:39 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18123 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index c73d29e..ec675a7 100644 (file)
@@ -539,6 +539,7 @@ sub fire_single_event {
     my $event_id = shift;
 
     my $e = OpenILS::Application::Trigger::Event->new($event_id);
+    OpenILS::Application::Trigger::Event->ClearObjectCache();
 
     if ($e->validate->valid) {
         $logger->info("trigger: Event is valid, reacting...");
@@ -567,6 +568,7 @@ sub fire_event_group {
     my $events = shift;
 
     my $e = OpenILS::Application::Trigger::EventGroup->new(@$events);
+    OpenILS::Application::Trigger::Event->ClearObjectCache();
 
     if ($e->validate->valid) {
         $logger->info("trigger: Event group is valid, reacting...");
@@ -679,6 +681,7 @@ sub grouped_events {
         $e->editor->disconnect;
     }
 
+    OpenILS::Application::Trigger::Event->ClearObjectCache();
     return \%groups;
 }
 __PACKAGE__->register_method(
@@ -737,8 +740,6 @@ sub run_all_events {
             $logger->info("trigger: run_all_events completed firing events for grouped event def=$def");
         }
     }
-                
-            
 }
 __PACKAGE__->register_method(
     api_name => 'open-ils.trigger.event.run_all_pending',
index fe70c5b..74ccf75 100644 (file)
@@ -444,6 +444,29 @@ sub _fm_class_by_hint {
     return $class;
 }
 
+my %_object_by_path_cache = ();
+sub ClearObjectCache {
+    for my $did ( keys %_object_by_path_cache ) {
+        my $phash = $_object_by_path_cache{$did};
+        for my $path ( keys %$phash ) {
+            my $shash = $phash{$path};
+            for my $step ( keys %$shash ) {
+                my $fhash = $shash{$step};
+                for my $ffield ( keys %$fhash ) {
+                    my $lhash = $fhash{$ffield};
+                    for my $lfield ( keys %$lhash ) {
+                        delete $$lhash{$lfield};
+                    }
+                    delete $$fhash{$ffield};
+                }
+                delete $$shash{$step};
+            }
+            delete $$phash{$path};
+        }
+        delete $_object_by_path_cache{$did};
+    }
+}
+        
 sub _object_by_path {
     my $self = shift;
     my $context = shift;
@@ -495,11 +518,14 @@ sub _object_by_path {
             $ed->xact_begin || return undef;
         }
 
-        $obj = $ed->$meth( 
-            ($multi) ?
-                { $ffield => $context->$lfield() } :
-                $context->$lfield()
-        );
+        $obj = $_object_by_path_cache{$self->event->event_def->id}{join('.',@$path)}{$step}{$ffield}{$context->$lfield()} ||
+            $ed->$meth( 
+                ($multi) ?
+                    { $ffield => $context->$lfield() } :
+                    $context->$lfield()
+            );
+
+        $_object_by_path_cache{$self->event->event_def->id}{join('.',@$path)}{$ffield}{$context->$lfield()} ||= $obj;
 
         if ($self->standalone) {
             $ed->xact_rollback || return undef;
index a5c742d..2a3c6c6 100644 (file)
@@ -28,7 +28,7 @@ sub new {
                     OpenILS::Application::Trigger::Event->new($_, $editor)
             } @ids
         ],
-        ids         => \@ids,
+        ids         => [ map { ref($_) ? $_->id : $_ } @ids ],
         editor      => $editor
     } => $class;