[open-ils-commits] r17905 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: . Trigger (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Sep 22 22:49:39 EDT 2010


Author: miker
Date: 2010-09-22 22:49:36 -0400 (Wed, 22 Sep 2010)
New Revision: 17905

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
Log:
Use a transaction to avoid talking to a replicated db when building A/T data structures

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm	2010-09-23 02:13:19 UTC (rev 17904)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm	2010-09-23 02:49:36 UTC (rev 17905)
@@ -45,6 +45,10 @@
 
     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 @@
         ])
     );
 
+    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 @@
     $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 @@
 
     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 @@
     );
 
     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) {

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm	2010-09-23 02:13:19 UTC (rev 17904)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm	2010-09-23 02:49:36 UTC (rev 17905)
@@ -57,13 +57,13 @@
     # 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,

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm	2010-09-23 02:13:19 UTC (rev 17904)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm	2010-09-23 02:49:36 UTC (rev 17905)
@@ -328,7 +328,7 @@
             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 @@
     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 @@
         $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 }
     );
 }



More information about the open-ils-commits mailing list