From 824ec751e212f8663cba14feb3ad872d2d0e045c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 14 May 2017 20:50:03 +0100 Subject: [PATCH] efficiency gains in set_canonical_ip --- lib/App/Netdisco/Core/Discover.pm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/App/Netdisco/Core/Discover.pm b/lib/App/Netdisco/Core/Discover.pm index 5ee71e92..1f26a226 100644 --- a/lib/App/Netdisco/Core/Discover.pm +++ b/lib/App/Netdisco/Core/Discover.pm @@ -58,18 +58,20 @@ sub set_canonical_ip { $new_ip = $revofname; } - if (ref {} eq ref setting('device_identity')) { - my $idmap = setting('device_identity') || {}; + if (ref {} eq ref setting('device_identity') + and scalar keys %{ setting('device_identity') }) { + my $idmap = setting('device_identity'); my $devips = $device->device_ips->order_by('alias'); ALIAS: while (my $alias = $devips->next) { + next if $alias->alias eq $old_ip; + foreach my $this (keys %$idmap) { $anded_this = [(ref $this ? @$this : $this), 'op:and']; + # lhs of device_identity matches device, rhs matches device_ip if (check_acl($device, $anded_this) - and check_acl($alias, $idmap->{$this}) - and $alias->alias ne $old_ip) { - + and check_acl($alias, $idmap->{$this})) { $new_ip = $alias->alias; last ALIAS; }