[open-ils-commits] r18519 - in trunk/Open-ILS/src/perlmods/OpenILS: . SIP (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 28 11:13:32 EDT 2010


Author: erickson
Date: 2010-10-28 11:13:30 -0400 (Thu, 28 Oct 2010)
New Revision: 18519

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/SIP.pm
   trunk/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
Log:
condensed SIP patron lookup by barcode into 1 cstore call;  provided option for slimmed-down user object fetching in the case of checkin, where all we really need is the barcode of the user on the circulation

Modified: trunk/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm	2010-10-28 15:10:53 UTC (rev 18518)
+++ trunk/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm	2010-10-28 15:13:30 UTC (rev 18519)
@@ -38,6 +38,7 @@
     my $class = shift;
     my $key   = (@_ > 1) ? shift : 'barcode';  # if we have multiple args, the first is the key index (default barcode)
     my $patron_id = shift;
+    my %args = @_;
 
     if ($key ne 'usr' and $key ne 'barcode') {
         syslog("LOG_ERROR", "Patron (card) lookup requested by illegeal key '$key'");
@@ -55,35 +56,44 @@
     syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s => %s): searching...", $key, $patron_id);
 
     my $e = OpenILS::SIP->editor();
+
+    my $usr_flesh = {
+        flesh => 2,
+        flesh_fields => {
+            au => [
+                "card",
+                "standing_penalties",
+                "addresses",
+                "billing_address",
+                "mailing_address",
+                'profile',
+            ],
+            ausp => ['standing_penalty']
+        }
+    };
+
+    # in some cases, we don't need all of this data.  Only fetch the user + barcode
+    $usr_flesh = {flesh => 1, flesh_fields => {au => ['card']}} if $args{slim_user};
     
-    my $user_id = $patron_id;
-    if($key eq 'barcode') {
-        my $card = $e->search_actor_card({barcode => $patron_id})->[0];
-        unless($card) {
+    my $user;
+    if($key eq 'barcode') { # retrieve user by barcode
+
+        $$usr_flesh{flesh} += 1;
+        $$usr_flesh{flesh_fields}{ac} = ['usr'];
+
+        my $card = $e->search_actor_card([{barcode => $patron_id}, $usr_flesh])->[0];
+
+        if(!$card) {
             syslog("LOG_WARNING", "No such patron barcode: $patron_id");
             return undef;
         }
-        $user_id = $card->usr;
+
+        $user = $card->usr;
+
+    } else {
+	    $user = $e->retrieve_actor_user([$patron_id, $usr_flesh]);
     }
 
-	my $user = $e->retrieve_actor_user([
-        $user_id,
-        {
-            flesh => 2,
-            flesh_fields => {
-                au => [
-                    "card",
-                    "standing_penalties",
-                    "addresses",
-                    "billing_address",
-                    "mailing_address",
-                    'profile',
-                ],
-                ausp => ['standing_penalty']
-            }
-        }
-    ]);
-
     if(!$user) {
         syslog("LOG_WARNING", "OILS: Unable to find patron %s => %s", $key, $patron_id);
         return undef;

Modified: trunk/Open-ILS/src/perlmods/OpenILS/SIP.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/SIP.pm	2010-10-28 15:10:53 UTC (rev 18518)
+++ trunk/Open-ILS/src/perlmods/OpenILS/SIP.pm	2010-10-28 15:13:30 UTC (rev 18519)
@@ -387,7 +387,7 @@
 	$xact->do_checkin( $self, $inst_id, $trans_date, $return_date, $current_loc, $item_props );
 	
 	if ($xact->ok) {
-        $xact->patron($self->find_patron(usr => $xact->{circ_user_id})) if $xact->{circ_user_id};
+        $xact->patron($self->find_patron(usr => $xact->{circ_user_id}, slim_user => 1)) if $xact->{circ_user_id};
         delete $item->{patron};
         delete $item->{due_date};
         syslog('LOG_INFO', "OILS: Checkin succeeded");



More information about the open-ils-commits mailing list