[open-ils-commits] r10424 - trunk/Open-ILS/src/support-scripts

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Aug 24 11:51:13 EDT 2008


Author: erickson
Date: 2008-08-24 11:51:06 -0400 (Sun, 24 Aug 2008)
New Revision: 10424

Modified:
   trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl
Log:
added a cache for org-from-address

Modified: trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl	2008-08-23 16:56:40 UTC (rev 10423)
+++ trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl	2008-08-24 15:51:06 UTC (rev 10424)
@@ -241,7 +241,34 @@
 }
 
 my %ORG_CACHE;
+my %ORG_FROM_CACHE;
 
+sub get_from_addr {
+    my $type = shift;
+    my $org_id = shift;
+    my $sender;
+
+    if(defined $ORG_FROM_CACHE{$org_id}) {
+        # we have we already loaded the setting for this org unit
+		$sender = $ORG_FROM_CACHE{$org_id};
+
+    } elsif(my $set = $e->search_actor_org_unit_setting( 
+			{name => 'org.bounced_emails', org_unit => $org_id} )->[0]) {
+		my $bemail = OpenSRF::Utils::JSON->JSON2perl($set->value);
+		$sender = $ORG_FROM_CACHE{$org_id} = $bemail if $bemail;
+	}
+
+    unless($sender) {
+        # there is no setting, use the configured sender
+        $sender = $settings->config_value(
+            notifications => $type => 'sender_address') || 
+            $settings->config_value(notifications => 'sender_address');
+        $ORG_FROM_CACHE{$org_id} = '';
+    }
+
+    return $sender;
+}
+
 sub generate_notice {
     my $notice = shift;
     my $type = shift;
@@ -250,17 +277,10 @@
     my $circ_list = fetch_circ_data(@circs);
     my $tt = Template->new({ABSOLUTE => 1});
 
-    my $sender = $settings->config_value(
-        notifications => $type => 'sender_address') || 
-        $settings->config_value(notifications => 'sender_address');
-
     # see if there is a configured bounce address for this org unit.
     # if so, use that as the sender
-	if(my $set = $e->search_actor_org_unit_setting( 
-			{name => 'org.bounced_emails', org_unit => $circ_list->[0]->circ_lib->id} )->[0]) {
-		my $bemail = OpenSRF::Utils::JSON->JSON2perl($set->value);
-		$sender = $bemail if $bemail;
-	}
+    my $org_id = $circ_list->[0]->circ_lib->id;
+    my $sender = get_from_addr($type, $org_id);
 
     my $context = {   
         circ_list => $circ_list,



More information about the open-ils-commits mailing list