From a393853e65380ab2d5cf8c4a746ffb430e2652f7 Mon Sep 17 00:00:00 2001 From: Irka Date: Tue, 12 Aug 2014 10:43:28 +0200 Subject: [PATCH] MT#5879 Fix memory issue Don't save or fetch data for all generated/sent invoices. Fetch data one-by-one. --- share/tools/generate_invoices.pl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/share/tools/generate_invoices.pl b/share/tools/generate_invoices.pl index 18e11e56a2..d14d978fe0 100755 --- a/share/tools/generate_invoices.pl +++ b/share/tools/generate_invoices.pl @@ -151,13 +151,14 @@ sub process_invoices{ if( my $billing_profile = get_billing_profile($client_contract, $stime, $etime) ){ if(my $invoice = generate_invoice_data($provider_contract,$provider_contact,$client_contract,$client_contact,$billing_profile, $stime, $etime)){ + $invoice->{data} = ''; push @{$invoices->{$client_contract->{id}}}, $invoice; } }else{#if billing profile $logger->debug( "No billing profile;\n"); } }else{ - $invoices->{$client_contract->{id}} = $dbh->selectall_arrayref('select invoices.* from invoices where invoices.generator="auto" + $invoices->{$client_contract->{id}} = $dbh->selectall_arrayref('select invoices.id from invoices where invoices.generator="auto" '.ifp(' and ', join(' and ', !$opt->{resend}?' invoices.sent_date is null ':(), @@ -403,7 +404,7 @@ sub generate_invoice_data{ $logger->debug( "generated data for invoice.id=".$invoice->{id}."; invoice.serial=".$invoice->{serial}.";\n" ); $invoice->{data} = $pdf; #set sent_date to null after each data regeneration - $dbh->do('update invoices set sent_date=?,data=?,amount_net=?,amount_vat=?,amount_total=? where id=?',undef,undef,@$invoice{qw/data amount_net amount_vat amount_total id/}); + $dbh->do('update invoices set sent_date=?,data=?,amount_net=?,amount_vat=?,amount_total=? where id=?',undef,undef,@$invoice{qw/data amount_net amount_vat amount_total id/}); return $invoice; } @@ -534,7 +535,10 @@ sub get_email_template{ } return $res; } - +sub get_invoice_data{ + my ($invoice,$data_ref) =@_; + $$data_ref = $dbh->selectrow_array('select data from invoices where id=?',undef,$invoice->{id}); +} sub email{ #todo: repeat my old function based on templates and store into utils my($email_template,$provider_contact,$client_contact,$client_invoices,$transport_in) = @_; @@ -560,6 +564,8 @@ sub email{ if($client_contact->{email}){ my @attachments = map { my $invoice = $_; + my $data = ''; + get_invoice_data($invoice,\$data); Email::MIME->create( attributes => { filename => "invoice_".$invoice->{serial}.".pdf", @@ -567,7 +573,7 @@ sub email{ encoding => "base64", disposition => "attachment", }, - body => $invoice->{data}, + body => $data, ); } @$client_invoices;