diff options
author | Mark Wells <mark@freeside.biz> | 2013-09-04 14:59:30 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-09-04 14:59:30 -0700 |
commit | d56135c1e98194db7ad91cb12ef5944543180a0e (patch) | |
tree | a3ea58935d871c624831440929f5316c4030f369 | |
parent | b389ce7f754dc37af90f97e11f8ec5b0b6c09842 (diff) |
optimize prepaid balance query, #24846
-rw-r--r-- | FS/FS/ClientAPI/PrepaidPhone.pm | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/FS/FS/ClientAPI/PrepaidPhone.pm b/FS/FS/ClientAPI/PrepaidPhone.pm index b05fb4fe4..2cea3c231 100644 --- a/FS/FS/ClientAPI/PrepaidPhone.pm +++ b/FS/FS/ClientAPI/PrepaidPhone.pm @@ -307,14 +307,8 @@ sub prepaid_phone_balance { foreach my $cust_svc ( @cust_svc ) { my $svc_x = $cust_svc->svc_x; - - #XXX optimization: a single SQL query to return the total amount - my $cdr_search = $svc_x->psearch_cdrs(%options); - $cdr_search->limit(1000); - $cdr_search->increment(0); - while ( my $cdr = $cdr_search->fetch ) { - $balance -= $cdr->rated_price; - } + my $sum_cdr = $svc_x->sum_cdrs(%options); + $balance += $sum_cdr->rated_price; } |