use new faster portvlanmismatch query without duplication

This commit is contained in:
Oliver Gorwits
2023-06-13 17:40:27 +01:00
parent 460b014e91
commit f14e495e49
3 changed files with 126 additions and 70 deletions

View File

@@ -21,24 +21,29 @@ get '/ajax/content/report/portvlanmismatch' => require_login sub {
my @results = schema(vars->{'tenant'})
->resultset('Virtual::PortVLANMismatch')->search({},{
bind => [ setting('sidebar_defaults')->{'device_ports'}->{'p_hide1002'}->{'default'}
? (1002, 1003, 1004, 1005, 1002, 1003, 1004, 1005, 1002, 1003, 1004, 1005, 1002, 1003, 1004, 1005) : (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) ],
? (1002, 1003, 1004, 1005) : (0, 0, 0, 0) ],
})
->hri->all;
# note that the generated list is rendered without HTML escape,
# so we MUST sanitise here with the grep
# # note that the generated list is rendered without HTML escape,
# # so we MUST sanitise here with the grep
# foreach my $res (@results) {
# my @left = grep {m/^(?:n:)?\d+$/} map {s/\s//g; $_} split ',', $res->{left_vlans};
# my @right = grep {m/^(?:n:)?\d+$/} map {s/\s//g; $_} split ',', $res->{right_vlans};
#
# my %new = (0 => [], 1 => []);
# my %cmp = listcmp @left, @right;
# foreach my $vlan (keys %cmp) {
# map { push @{ $new{$_} }, ( (2 == scalar @{ $cmp{$vlan} }) ? $vlan : "<strong>$vlan</strong>" ) } @{ $cmp{$vlan} };
# }
#
# $res->{left_vlans} = join ', ', sort_by { (my $a = $_) =~ s/\D//g; sprintf "%05d", $a } @{ $new{0} };
# $res->{right_vlans} = join ', ', sort_by { (my $a = $_) =~ s/\D//g; sprintf "%05d", $a } @{ $new{1} };
# }
foreach my $res (@results) {
my @left = grep {m/^(?:n:)?\d+$/} map {s/\s//g; $_} split ',', $res->{left_vlans};
my @right = grep {m/^(?:n:)?\d+$/} map {s/\s//g; $_} split ',', $res->{right_vlans};
my %new = (0 => [], 1 => []);
my %cmp = listcmp @left, @right;
foreach my $vlan (keys %cmp) {
map { push @{ $new{$_} }, ( (2 == scalar @{ $cmp{$vlan} }) ? $vlan : "<strong>$vlan</strong>" ) } @{ $cmp{$vlan} };
}
$res->{left_vlans} = join ', ', sort_by { (my $a = $_) =~ s/\D//g; sprintf "%05d", $a } @{ $new{0} };
$res->{right_vlans} = join ', ', sort_by { (my $a = $_) =~ s/\D//g; sprintf "%05d", $a } @{ $new{1} };
$res->{only_left_vlans} = join ', ', @{ $res->{only_left_vlans} || [] };
$res->{only_right_vlans} = join ', ', @{ $res->{only_right_vlans} || [] };
}
if (request->is_ajax) {