TT#98650 speedup redis locaction search by id

instantiation a redis location resultset can cause
a scan if no filter args are provided.

Change-Id: I398398115011774c20fdecbc675223a22b9e1917
mr9.1
Rene Krenn 5 years ago
parent 258a54de88
commit b4281d4ee8

@ -14,14 +14,15 @@ use NGCP::Panel::Utils::Kamailio;
use NGCP::Panel::Utils::Subscriber; use NGCP::Panel::Utils::Subscriber;
sub _item_rs { sub _item_rs {
my ($self, $c) = @_; my ($self, $c, $filter) = @_;
my $item_rs; my $item_rs;
if ($c->config->{redis}->{usrloc}) { if ($c->config->{redis}->{usrloc}) {
# TODO: will this survive with like 1M records? # TODO: will this survive with like 1M records?
my $filter = {}; unless (defined $filter) {
$filter = {};
if ($c->req->param('subscriber_id')) { if ($c->req->param('subscriber_id')) {
my $sub = $c->model('DB')->resultset('voip_subscribers')->find($c->req->param('subscriber_id')); my $sub = $c->model('DB')->resultset('voip_subscribers')->find($c->req->param('subscriber_id'));
if ($sub) { if ($sub) {
@ -44,6 +45,7 @@ sub _item_rs {
} elsif ($c->user->roles eq "reseller" || $c->user->roles eq "ccare") { } elsif ($c->user->roles eq "reseller" || $c->user->roles eq "ccare") {
$filter->{reseller_id} = $c->user->reseller_id; $filter->{reseller_id} = $c->user->reseller_id;
} }
}
$item_rs = NGCP::Panel::Utils::Subscriber::get_subscriber_location_rs($c, $filter); $item_rs = NGCP::Panel::Utils::Subscriber::get_subscriber_location_rs($c, $filter);
} else { } else {
my @joins = (); my @joins = ();
@ -136,7 +138,7 @@ sub resource_from_item {
sub item_by_id { sub item_by_id {
my ($self, $c, $id) = @_; my ($self, $c, $id) = @_;
my $item_rs = $self->item_rs($c); my $item_rs = $self->item_rs($c,{ id => $id, });
return $item_rs->find($id); return $item_rs->find($id);
} }

@ -51,7 +51,7 @@ sub get_subscriber_location_rs {
} }
$redis->select($c->config->{redis}->{usrloc_db}); $redis->select($c->config->{redis}->{usrloc_db});
my $rs = NGCP::Panel::Utils::RedisLocationResultSet->new(_redis => $redis, _c => $c); my $rs = NGCP::Panel::Utils::RedisLocationResultSet->new(_redis => $redis, _c => $c);
$rs = $rs->search($filter) if $filter; $rs = $rs->search($filter) if ($filter and scalar keys %$filter);
return $rs; return $rs;
} catch($e) { } catch($e) {
$c->log->error("Failed to fetch location information from redis: $e"); $c->log->error("Failed to fetch location information from redis: $e");

Loading…
Cancel
Save