From 9d3c95084d963fc5cf171b02110a79911913b83e Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 23 Sep 2010 02:49:36 +0000 Subject: [PATCH] Use a transaction to avoid talking to a replicated db when building A/T data structures git-svn-id: svn://svn.open-ils.org/ILS/trunk@17905 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Trigger.pm | 6 ++--- .../perlmods/OpenILS/Application/Trigger/Event.pm | 28 +++++++++++++++++++++- .../OpenILS/Application/Trigger/Reactor.pm | 4 ++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm index a4d022ac6..78868cba0 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm @@ -328,7 +328,7 @@ sub events_by_target { for (grep { $_ ne '-and' } keys %{$$filter{event}}); } - my $e = new_editor(); + my $e = new_editor(xact=>1); my $events = $e->json_query($query); @@ -595,8 +595,6 @@ sub pending_events { my $client = shift; my $granularity = shift; - my $editor = new_editor(); - my $query = [{ state => 'pending', run_time => {'<' => 'now'} }, { order_by => { atev => [ qw/run_time add_time/] }, 'join' => 'atevdef' }]; if (defined $granularity) { @@ -605,7 +603,7 @@ sub pending_events { $query->[0]->{'+atevdef'} = {granularity => undef}; } - return $editor->search_action_trigger_event( + return new_editor(xact=>1)->search_action_trigger_event( $query, { idlist=> 1, timeout => 7200, substream => 1 } ); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm index 244df30db..3a635ec3c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm @@ -45,6 +45,10 @@ sub init { return $self if (!$self->id); + if ($self->standalone) { + $self->editor->xact_begin || return undef; + } + $self->event( $self->editor->retrieve_action_trigger_event([ $self->id, { @@ -57,6 +61,10 @@ sub init { ]) ); + if ($self->standalone) { + $self->editor->xact_rollback || return undef; + } + $self->user_data(OpenSRF::Utils::JSON->JSON2perl( $self->event->user_data )) if (defined( $self->event->user_data )); @@ -91,8 +99,16 @@ sub init { $meth =~ s/Fieldmapper:://; $meth =~ s/::/_/; + if ($self->standalone) { + $self->editor->xact_begin || return undef; + } + $self->target( $self->editor->$meth( $self->event->target ) ); + if ($self->standalone) { + $self->editor->xact_rollback || return undef; + } + return $self; } @@ -463,7 +479,7 @@ sub _object_by_path { my $ed = grep( /open-ils.cstore/, @{$fclass->Controller} ) ? $self->editor : - new_rstore_editor(); + new_rstore_editor(($self->standalone ? () : (xact=>1))); my $obj = $context->$step(); @@ -473,11 +489,21 @@ sub _object_by_path { ); if (!ref $obj) { + + if ($self->standalone) { + $ed->xact_begin || return undef; + } + $obj = $ed->$meth( ($multi) ? { $ffield => $context->$lfield() } : $context->$lfield() ); + + if ($self->standalone) { + $ed->xact_rollback || return undef; + } + } if (@$path) { diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm index 840964dde..5cc31002b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm @@ -57,13 +57,13 @@ my $_TT_helpers = { # returns the calculated copy price get_copy_price => sub { my $copy_id = shift; - return $U->get_copy_price(new_editor(), $copy_id); + return $U->get_copy_price(new_editor(xact=>1), $copy_id); }, # given a copy, returns the title and author in a hash get_copy_bib_basics => sub { my $copy_id = shift; - my $copy = new_editor()->retrieve_asset_copy([ + my $copy = new_editor(xact=>1)->retrieve_asset_copy([ $copy_id, { flesh => 2, -- 2.11.0