From: miker Date: Fri, 1 Oct 2010 19:39:51 +0000 (+0000) Subject: Implement a process-local cache for event target fleshing -- particularly helpful... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a3b4dee7b9ed9f45eefe26858e47dc98c711ab47;p=evergreen%2Fbjwebb.git Implement a process-local cache for event target fleshing -- particularly helpful with large event groups git-svn-id: svn://svn.open-ils.org/ILS/trunk@18123 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm index c73d29ed6..ec675a7a3 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm @@ -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', diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm index fe70c5b02..74ccf7544 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm @@ -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; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm index a5c742dc0..2a3c6c632 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm @@ -28,7 +28,7 @@ sub new { OpenILS::Application::Trigger::Event->new($_, $editor) } @ids ], - ids => \@ids, + ids => [ map { ref($_) ? $_->id : $_ } @ids ], editor => $editor } => $class;