[open-ils-commits] r16551 - in branches/rel_1_6/Open-ILS/src/perlmods/OpenILS: . SIP Utils (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jun 1 16:40:30 EDT 2010


Author: erickson
Date: 2010-06-01 16:40:25 -0400 (Tue, 01 Jun 2010)
New Revision: 16551

Modified:
   branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP.pm
   branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
   branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm
Log:
backporting 16544: in the SIP server plugin, don't connect and start a transaction by default with every cstore handle.  only connect/begin when necessary.  also, making use of new CStoreEditor::init() call for setting up the editor environment when initial load was done before the IDL was available.  Also, back-porting Joe A's CStoreEditor cleanup changes, namely the new init() routine.

Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm	2010-06-01 20:35:21 UTC (rev 16550)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm	2010-06-01 20:40:25 UTC (rev 16551)
@@ -509,17 +509,20 @@
 sub block {
 	my ($self, $card_retained, $blocked_card_msg) = @_;
 
+    my $e = $self->{editor};
 	my $u = $self->{user};
-	my $e = $self->{editor} = OpenILS::SIP->reset_editor();
 
 	syslog('LOG_INFO', "OILS: Blocking user %s", $u->card->barcode );
 
 	return $self if $u->card->active eq 'f';
 
+    # connect and start a new transaction
+    $e->xact_begin;
+
 	$u->card->active('f');
 	if( ! $e->update_actor_card($u->card) ) {
 		syslog('LOG_ERR', "OILS: Block card update failed: %s", $e->event->{textcode});
-		$e->xact_rollback;
+		$e->rollback; # rollback + disconnect
 		return $self;
 	}
 
@@ -532,15 +535,14 @@
 
 	if( ! $e->update_actor_user($u) ) {
 		syslog('LOG_ERR', "OILS: Block: patron alert update failed: %s", $e->event->{textcode});
-		$e->xact_rollback;
+		$e->rollback; # rollback + disconnect
 		return $self;
 	}
 
 	# stay in synch
 	$self->{user}->alert_message( $note );
 
-	$e->commit; # commits and resets
-	$self->{editor} = OpenILS::SIP->reset_editor();
+	$e->commit; # commits and disconnects
 	return $self;
 }
 

Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP.pm	2010-06-01 20:35:21 UTC (rev 16550)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/SIP.pm	2010-06-01 20:40:25 UTC (rev 16551)
@@ -78,34 +78,20 @@
 }
 
 sub editor {
-	return $editor 
-		if $editor and $editor->{session}
-		and $editor->session->connected;
 	return $editor = make_editor();
 }
 
-sub reset_editor {
-	$editor = undef;
-	return editor();
-}
-
 sub config {
 	return $config;
 }
 
 
 # Creates the global editor object
+my $cstore_init = 1; # call init on first use
 sub make_editor {
-	require OpenILS::Utils::CStoreEditor;
-	my $e = OpenILS::Utils::CStoreEditor->new(xact => 1);
-	# gnarly cstore hack to re-gen autogen methods after IDL is loaded
-	if(!UNIVERSAL::can($e, 'search_actor_card')) {
-		syslog("LOG_WARNING", "OILS: Reloading CStoreEditor...");
-		delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
-		require OpenILS::Utils::CStoreEditor;
-		$e = OpenILS::Utils::CStoreEditor->new(xact =>1);
-	}
-	return $e;
+    OpenILS::Utils::CStoreEditor::init() if $cstore_init;
+    $cstore_init = 0;
+	return OpenILS::Utils::CStoreEditor->new;
 }
 
 =head2 clean_text(scalar)

Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm	2010-06-01 20:35:21 UTC (rev 16550)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm	2010-06-01 20:40:25 UTC (rev 16551)
@@ -361,7 +361,7 @@
             $self->log(D,"running in substream mode");
             $val = [];
             while( my $resp = $req->recv(timeout => $self->timeout) ) {
-                push(@$val, $resp->content) if $resp->content;
+                push(@$val, $resp->content) if $resp->content and not $self->discard;
             }
 
         } else {
@@ -391,7 +391,17 @@
    return $self->{substream};
 }
 
+# -----------------------------------------------------------------------------
+# discard response data instead of returning it to the caller.  currently only 
+# works in conjunction with substream mode.  
+# -----------------------------------------------------------------------------
+sub discard {
+   my( $self, $bool ) = @_;
+   $self->{discard} = $bool if defined $bool;
+   return $self->{discard};
+}
 
+
 # -----------------------------------------------------------------------------
 # Sets / Returns the requestor object.  This is set when checkauth succeeds.
 # -----------------------------------------------------------------------------
@@ -661,6 +671,7 @@
 
     $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
     $self->timeout($$options{timeout});
+    $self->discard($$options{discard});
 
 	# remove any stale events
 	$self->clear_event;
@@ -767,47 +778,22 @@
 # -------------------------------------------------------------
 # Load up the methods from the FM classes
 # -------------------------------------------------------------
-my $map = $Fieldmapper::fieldmap;
-for my $object (keys %$map) {
-	my $obj = __fm2meth($object,'_');
-	my $type = __fm2meth($object, '.');
 
-	my $update = "update_$obj";
-	my $updatef = 
-		"sub $update {return shift()->runmethod('update', '$type', \@_);}";
-	eval $updatef;
-
-	my $retrieve = "retrieve_$obj";
-	my $retrievef = 
-		"sub $retrieve {return shift()->runmethod('retrieve', '$type', \@_);}";
-	eval $retrievef;
-
-	my $search = "search_$obj";
-	my $searchf = 
-		"sub $search {return shift()->runmethod('search', '$type', \@_);}";
-	eval $searchf;
-
-	my $create = "create_$obj";
-	my $createf = 
-		"sub $create {return shift()->runmethod('create', '$type', \@_);}";
-	eval $createf;
-
-	my $delete = "delete_$obj";
-	my $deletef = 
-		"sub $delete {return shift()->runmethod('delete', '$type', \@_);}";
-	eval $deletef;
-
-	my $bretrieve = "batch_retrieve_$obj";
-	my $bretrievef = 
-		"sub $bretrieve {return shift()->runmethod('batch_retrieve', '$type', \@_);}";
-	eval $bretrievef;
-
-	my $retrieveall = "retrieve_all_$obj";
-	my $retrieveallf = 
-		"sub $retrieveall {return shift()->runmethod('retrieve_all', '$type', \@_);}";
-	eval $retrieveallf;
+sub init {
+    no warnings;    #  Here we potentially redefine subs via eval
+    my $map = $Fieldmapper::fieldmap;
+    for my $object (keys %$map) {
+        my $obj  = __fm2meth($object, '_');
+        my $type = __fm2meth($object, '.');
+        foreach my $command (qw/ update retrieve search create delete batch_retrieve retrieve_all /) {
+            eval "sub ${command}_$obj {return shift()->runmethod('$command', '$type', \@_);}\n";
+        }
+        # TODO: performance test against concatenating a big string of all the subs and eval'ing only ONCE.
+    }
 }
 
+init();  # Add very many subs to this namespace
+
 sub json_query {
     my( $self, $arg, $options ) = @_;
     $options ||= {};
@@ -816,6 +802,7 @@
     $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
 
     $self->timeout($$options{timeout});
+    $self->discard($$options{discard});
 	$self->clear_event;
     my $obj;
     my $err;



More information about the open-ils-commits mailing list