MT#9329 Use DB to count statistic for calls.

Optimization in case when calls dispersion is low.
changes/94/294/1
Irina Peshinskaya 11 years ago
parent 76129383f5
commit bf9ed81fd2

@ -29,7 +29,6 @@ sub calls_matrix_ajax :Chained('/') :PathPart('calls/ajax') :Args(0) {
my $matrix = [];
my $countries = [];
my $from = $c->req->params->{from};
my $to = $c->req->params->{to};
my $parse_time = DateTime::Format::Strptime->new(pattern => '%F');
@ -53,14 +52,15 @@ sub calls_matrix_ajax :Chained('/') :PathPart('calls/ajax') :Args(0) {
start_time => { '<=' => $to_epoch },
],
}, {
select => [qw/source_cli destination_user_in/],
select => [qw/source_cli destination_user_in/,
{ count => '*', -as => 'cnt' },
],
group_by => [qw/source_cli destination_user_in/],
});
my $n = $rs->count;
my $id_counter = 0;
my $id_table = {};
my $i = 0;
while(my $ref = $rs->next) {
next unless($ref->source_cli && $ref->source_cli =~ /^\d{5,}$/ &&
$ref->destination_user_in && $ref->destination_user_in =~ /^\d{5,}$/);
@ -87,12 +87,11 @@ sub calls_matrix_ajax :Chained('/') :PathPart('calls/ajax') :Args(0) {
$matrix->[$sid] = [];
}
unless(defined $matrix->[$sid]->[$did]) {
$matrix->[$sid]->[$did] = 1;
$matrix->[$sid]->[$did] = 0 + $ref->get_column('cnt');
} else {
$matrix->[$sid]->[$did]++;
$matrix->[$sid]->[$did] += $ref->get_column('cnt');
}
}
my $count = @{ $countries };
for(my $i = 0; $i < $count; ++$i) {
unless(defined $matrix->[$i]) {
@ -102,7 +101,6 @@ sub calls_matrix_ajax :Chained('/') :PathPart('calls/ajax') :Args(0) {
$matrix->[$i]->[$count-1] = undef;
}
}
my $data = {
countries => $countries,
calls => $matrix,

Loading…
Cancel
Save