diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index 1a60b99ff6..444ea389d0 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -673,67 +673,78 @@ sub preferences :Chained('base') :PathPart('preferences') :Args(0) { my $prov_subscriber = $c->stash->{subscriber}->provisioning_voip_subscriber; my $cfs = {}; - foreach my $type(qw/cfu cfna cft cfb cfs cfr cfo/) { - my $maps = $prov_subscriber->voip_cf_mappings - ->search({ type => $type }); - $cfs->{$type} = []; - foreach my $map($maps->all) { - my @dset = (); - my $dset_name = undef; - if($map->destination_set) { - @dset = map { { $_->get_columns } } $map->destination_set->voip_cf_destinations->search({}, - { order_by => { -asc => 'priority' }})->all; - foreach my $d(@dset) { - $d->{as_string} = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d, $prov_subscriber); - } - $dset_name = $map->destination_set->name; + my $start = time(); + my $maps = $prov_subscriber->voip_cf_mappings->search(undef, + { + prefetch => [ + {destination_set => 'voip_cf_destinations'}, + {time_set => 'voip_cf_periods'}, + {source_set => 'voip_cf_sources'}, + {bnumber_set => 'voip_cf_bnumbers'} + ] + }); + + foreach my $map($maps->all) { + my @dset = (); + my $dset_name = undef; + if($map->destination_set) { + @dset = map { { $_->get_columns } } $map->destination_set->voip_cf_destinations->search({}, + { order_by => { -asc => 'priority' }})->all; + foreach my $d(@dset) { + $d->{as_string} = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d, $prov_subscriber); } - my @tset = (); - my $tset_name = undef; - if($map->time_set) { - @tset = map { { $_->get_columns } } $map->time_set->voip_cf_periods->all; - foreach my $t(@tset) { - $t->{as_string} = NGCP::Panel::Utils::Subscriber::period_as_string($t); - } - $tset_name = $map->time_set->name; + $dset_name = $map->destination_set->name; + } + my @tset = (); + my $tset_name = undef; + if($map->time_set) { + @tset = map { { $_->get_columns } } $map->time_set->voip_cf_periods->all; + foreach my $t(@tset) { + $t->{as_string} = NGCP::Panel::Utils::Subscriber::period_as_string($t); } - my @sources = (); - my $sset_name = undef; - my $sset_mode = undef; - if($map->source_set) { - @sources = map { { $_->get_columns } } $map->source_set->voip_cf_sources->all; - foreach my $s(@sources) { - $s->{as_string} = $s->{source}; - } - $sset_name = $map->source_set->name; - $sset_mode = $map->source_set->mode; + $tset_name = $map->time_set->name; + } + my @sources = (); + my $sset_name = undef; + my $sset_mode = undef; + if($map->source_set) { + @sources = map { { $_->get_columns } } $map->source_set->voip_cf_sources->all; + foreach my $s(@sources) { + $s->{as_string} = $s->{source}; } - my @bnumbers = (); - my $bset_name = undef; - my $bset_mode = undef; - if($map->bnumber_set) { - @bnumbers = map { { $_->get_columns } } $map->bnumber_set->voip_cf_bnumbers->all; - foreach my $s(@bnumbers) { - $s->{as_string} = $s->{bnumber}; - } - $bset_name = $map->bnumber_set->name; - $bset_mode = $map->bnumber_set->mode; + $sset_name = $map->source_set->name; + $sset_mode = $map->source_set->mode; + } + my @bnumbers = (); + my $bset_name = undef; + my $bset_mode = undef; + if($map->bnumber_set) { + @bnumbers = map { { $_->get_columns } } $map->bnumber_set->voip_cf_bnumbers->all; + foreach my $s(@bnumbers) { + $s->{as_string} = $s->{bnumber}; } - push @{ $cfs->{$type} }, { - destinations => \@dset, - dset_name => $dset_name, - periods => \@tset, - tset_name => $tset_name, - sources => \@sources, - sset_name => $sset_name, - sset_mode => $sset_mode, - bset_name => $bset_name, - bset_mode => $bset_mode, - bnumbers => \@bnumbers, - enabled => $map->enabled, - }; + $bset_name = $map->bnumber_set->name; + $bset_mode = $map->bnumber_set->mode; } + push @{ $cfs->{$map->type} }, { + destinations => \@dset, + dset_name => $dset_name, + periods => \@tset, + tset_name => $tset_name, + sources => \@sources, + sset_name => $sset_name, + sset_mode => $sset_mode, + bset_name => $bset_name, + bset_mode => $bset_mode, + bnumbers => \@bnumbers, + enabled => $map->enabled, + }; } + + my $end = time(); + + warn sprintf("Execution Time: %0.02f s\n", $end - $start); + $c->stash(cf_destinations => $cfs); my $ringtimeout_preference = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( diff --git a/lib/NGCP/Panel/Role/API/CFMappings.pm b/lib/NGCP/Panel/Role/API/CFMappings.pm index e2e91563fe..ce711f792c 100644 --- a/lib/NGCP/Panel/Role/API/CFMappings.pm +++ b/lib/NGCP/Panel/Role/API/CFMappings.pm @@ -27,14 +27,25 @@ sub hal_from_item { my $resource = { subscriber_id => $item->id, cfu => [], cfb => [], cfna => [], cft => [], cfs => [], cfr => [], cfo => []}; my $b_subs_id = $item->id; - my $p_subs_id = $item->provisioning_voip_subscriber->id; + my $prov_subscriber = $item->provisioning_voip_subscriber; + my $p_subs_id = $prov_subscriber->id; my $ringtimeout_preference = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( - c => $c, attribute => 'ringtimeout', prov_subscriber => $item->provisioning_voip_subscriber)->first; + c => $c, attribute => 'ringtimeout', prov_subscriber => $prov_subscriber)->first; $ringtimeout_preference = $ringtimeout_preference ? $ringtimeout_preference->value : undef; unless ($params->{skip_existing}) { - for my $mapping ($item->provisioning_voip_subscriber->voip_cf_mappings->all) { + my $mappings = $prov_subscriber->voip_cf_mappings->search(undef, + { + prefetch => [ + {destination_set => 'voip_cf_destinations'}, + {time_set => 'voip_cf_periods'}, + {source_set => 'voip_cf_sources'}, + {bnumber_set => 'voip_cf_bnumbers'} + ] + } + ); + for my $mapping ($mappings->all) { push @{ $resource->{$mapping->type} }, { $mapping->destination_set ? ( destinationset => $mapping->destination_set->name,