Use cursor to speed up get_port_macs(). This provides a significant performance improvement in both macsuck and macwalk operations especially in deployments with a large number of devices and device interfaces.
This commit is contained in:
@@ -32,22 +32,29 @@ sub get_port_macs {
|
|||||||
my $device = shift;
|
my $device = shift;
|
||||||
my $port_macs = {};
|
my $port_macs = {};
|
||||||
|
|
||||||
unless ($device->in_storage) {
|
unless ( $device->in_storage ) {
|
||||||
debug sprintf ' [%s] get_port_macs - skipping device not yet discovered',
|
debug sprintf
|
||||||
|
' [%s] get_port_macs - skipping device not yet discovered',
|
||||||
$device->ip;
|
$device->ip;
|
||||||
return $port_macs;
|
return $port_macs;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dp_macs = schema('netdisco')->resultset('DevicePort')
|
my $dp_macs
|
||||||
->search({ mac => { '!=' => undef} });
|
= schema('netdisco')->resultset('DevicePort')
|
||||||
while (my $r = $dp_macs->next) {
|
->search( { mac => { '!=' => undef } },
|
||||||
$port_macs->{ $r->mac } = $r->ip;
|
{ select => [ 'mac', 'ip' ] } );
|
||||||
|
my $dp_cursor = $dp_macs->cursor;
|
||||||
|
while ( my @vals = $dp_cursor->next ) {
|
||||||
|
$port_macs->{ $vals[0] } = $vals[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
my $d_macs = schema('netdisco')->resultset('Device')
|
my $d_macs
|
||||||
->search({ mac => { '!=' => undef} });
|
= schema('netdisco')->resultset('Device')
|
||||||
while (my $r = $d_macs->next) {
|
->search( { mac => { '!=' => undef } },
|
||||||
$port_macs->{ $r->mac } = $r->ip;
|
{ select => [ 'mac', 'ip' ] } );
|
||||||
|
my $d_cursor = $d_macs->cursor;
|
||||||
|
while ( my @vals = $d_cursor->next ) {
|
||||||
|
$port_macs->{ $vals[0] } = $vals[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $port_macs;
|
return $port_macs;
|
||||||
|
|||||||
Reference in New Issue
Block a user