MT#16321 The smallest changes for particular billing_mappings speed

Just against ticket issue: subscribers API

Change-Id: I77956ac0d0813437824fa83132d1400eba3d2196
changes/82/3582/1
Irina Peshinskaya 10 years ago
parent 2da07ec259
commit 11256183bd

@ -178,16 +178,17 @@ sub item_by_id {
sub get_customer {
my ($self, $c, $customer_id) = @_;
my $customer = NGCP::Panel::Utils::Contract::get_contract_rs(
my $customer_rs = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'),
contract_id => $customer_id,
);
$customer = $customer->search({
$customer_rs = $customer_rs->search({
'contact.reseller_id' => { '-not' => undef },
'me.id' => $customer_id,
},{
join => 'contact',
});
$customer = $customer->search({
$customer_rs = $customer_rs->search({
'-or' => [
'product.class' => 'sipaccount',
'product.class' => 'pbxaccount',
@ -198,11 +199,11 @@ sub get_customer {
});
if($c->user->roles eq "admin") {
} elsif($c->user->roles eq "reseller") {
$customer = $customer->search({
$customer_rs = $customer_rs->search({
'contact.reseller_id' => $c->user->reseller_id,
});
}
$customer = $customer->first;
my $customer = $customer_rs->first;
unless($customer) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'customer_id', doesn't exist.");
return;

@ -108,14 +108,14 @@ sub recursively_lock_contract {
sub get_contract_rs {
my %params = @_;
my ($schema,$now) = @params{qw/schema now/};
my ($schema,$now,$contract_id) = @params{qw/schema now contract_id/};
$now //= NGCP::Panel::Utils::DateTime::current_local;
my $dtf = $schema->storage->datetime_parser;
my $rs = $schema->resultset('contracts')
->search({
$params{include_terminated} ? () : ('me.status' => { '!=' => 'terminated' }),
},{
bind => [ ( $dtf->format_datetime($now) ) x 2],
bind => [ ( $dtf->format_datetime($now) ) x 2, ( $contract_id ) x 2 ],
'join' => { 'billing_mappings_actual' => { 'billing_mappings' => 'product'}},
'+select' => [
'billing_mappings.id',
@ -135,11 +135,12 @@ sub get_contract_rs {
sub get_customer_rs {
my %params = @_;
my ($c,$now) = @params{qw/c now/};
my ($c,$now,$contract_id) = @params{qw/c now contract_id/};
my $customers = get_contract_rs(
schema => $c->model('DB'),
include_terminated => $params{include_terminated},
contract_id => $contract_id,
);
$customers = $customers->search({

@ -909,7 +909,7 @@ sub get_actual_billing_mapping {
my $contract_create = NGCP::Panel::Utils::DateTime::set_local_tz($contract->create_timestamp // $contract->modify_timestamp);
my $dtf = $schema->storage->datetime_parser;
$now = $contract_create if $now < $contract_create; #if there is no mapping starting with or before $now, it would returns the mapping with max(id):
return $schema->resultset('billing_mappings_actual')->search({ contract_id => $contract->id },{bind => [ ( $dtf->format_datetime($now) ) x 2],})->first;
return $schema->resultset('billing_mappings_actual')->search({ contract_id => $contract->id },{bind => [ ( $dtf->format_datetime($now) ) x 2, ($contract->id) x 2 ],})->first;
}
sub set_subscriber_lock_level {

Loading…
Cancel
Save