diff options
author | ivan <ivan> | 2011-11-14 20:36:03 +0000 |
---|---|---|
committer | ivan <ivan> | 2011-11-14 20:36:03 +0000 |
commit | 98276fe350fca1003e83c33f5270a2e83dec2f02 (patch) | |
tree | d3de9b7fcbf55a634826c0e7a6ff4c3795bd80dd /FS | |
parent | d388634fe71d7b2ced26ec495af72a811257b5b5 (diff) |
optimize invoice rendering with lots of CDRs, RT#15155
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_bill_pkg.pm | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index adc09d7a7..9cc6e7cab 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -826,11 +826,10 @@ usage. sub usage { my( $self, $classnum ) = @_; my $sum = 0; - my @values = (); if ( $self->get('details') ) { - @values = + foreach my $value ( map { ref($_) eq 'HASH' ? $_->{'amount'} : $_->[2] @@ -843,20 +842,26 @@ sub usage { : 1 ) } - @{ $self->get('details') }; + @{ $self->get('details') } + ) { + $sum += $value if $value; + } + + return $sum; } else { - my $hashref = { 'billpkgnum' => $self->billpkgnum }; - $hashref->{ 'classnum' } = $classnum if defined($classnum); - @values = map { $_->amount } qsearch('cust_bill_pkg_detail', $hashref); + my $sql = 'SELECT SUM(COALESCE(amount,0)) FROM cust_bill_pkg_detail '. + ' WHERE billpkgnum = '. $self->billpkgnum; + $sql .= " AND classnum = $classnum" if defined($classnum); - } + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + + return $sth->fetchrow_arrayref->[0]; - foreach ( @values ) { - $sum += $_ if $_; } - $sum; + } =item usage_classes |