From e81fcc3454632f6a60173a139cb6be268658c4ea Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 4 Jan 2012 01:17:40 +0000 Subject: [PATCH] optimize CDR rating after timed rate perf regression, RT#15739 --- FS/FS/Schema.pm | 4 +++- FS/FS/cdr.pm | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index c2f40f64e..78d88dd2b 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2692,7 +2692,9 @@ sub tables_hashref { ], 'primary_key' => 'ratedetailnum', 'unique' => [ [ 'ratenum', 'orig_regionnum', 'dest_regionnum' ] ], - 'index' => [ [ 'ratenum', 'dest_regionnum' ] ], + 'index' => [ [ 'ratenum', 'dest_regionnum' ], + [ 'ratenum', 'ratetimenum' ] + ], }, 'rate_region' => { diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 842cfab6c..ff07a59ee 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -692,8 +692,11 @@ sub rate_prefix { if ( !exists($interval_cache{$regionnum}) ) { my @intervals = ( sort { $a->stime <=> $b->stime } - map { my $r = $_->rate_time; $r ? $r->intervals : () } - $rate->rate_detail + map { $_->rate_time->intervals } + qsearch({ 'table' => 'rate_detail', + 'hashref' => { 'ratenum' => $rate->ratenum }, + 'extra_sql' => 'AND ratetimenum IS NOT NULL', + }) ); $interval_cache{$regionnum} = \@intervals; warn " cached ".scalar(@intervals)." interval(s)\n" @@ -1256,6 +1259,7 @@ CDR reprocessing. sub clear_status { my $self = shift; + my %opt = @_; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -1271,6 +1275,7 @@ sub clear_status { if ( $cdr_prerate && $cdr_prerate_cdrtypenums{$self->cdrtypenum} && $self->rated_ratedetailnum #avoid putting old CDRs back in "rated" && $self->freesidestatus eq 'done' + && ! $opt{'rerate'} ) { #special case $self->freesidestatus('rated'); -- 2.11.0