From 55055688918c99b89005cff45446ebf601c42f02 Mon Sep 17 00:00:00 2001 From: erickson Date: Sun, 24 Aug 2008 15:51:06 +0000 Subject: [PATCH] added a cache for org-from-address git-svn-id: svn://svn.open-ils.org/ILS/trunk@10424 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../support-scripts/generate_circ_notices.pl | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/support-scripts/generate_circ_notices.pl b/Open-ILS/src/support-scripts/generate_circ_notices.pl index 4294d0a90c..57dcd9f107 100755 --- a/Open-ILS/src/support-scripts/generate_circ_notices.pl +++ b/Open-ILS/src/support-scripts/generate_circ_notices.pl @@ -241,6 +241,33 @@ sub process_circs { } 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; @@ -250,17 +277,10 @@ sub generate_notice { 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, -- 2.43.2