[freeside-commits] freeside/FS/FS cust_bill_pkg.pm,1.61,1.62

Ivan,,, ivan at wavetail.420.am
Mon Nov 14 12:36:03 PST 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv6424

Modified Files:
	cust_bill_pkg.pm 
Log Message:
optimize invoice rendering with lots of CDRs, RT#15155

Index: cust_bill_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill_pkg.pm,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -w -d -r1.61 -r1.62
--- cust_bill_pkg.pm	14 Nov 2011 04:27:56 -0000	1.61
+++ cust_bill_pkg.pm	14 Nov 2011 20:36:00 -0000	1.62
@@ -826,11 +826,10 @@
 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 @@
                             : 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



More information about the freeside-commits mailing list