[#156] Only delete node_ip and node_nbt when no active nodes reference

I'm a bit wary that this will slow things down horribly.
This commit is contained in:
Oliver Gorwits
2014-11-13 23:42:24 +00:00
parent bf27489a87
commit e3f5022caa
2 changed files with 22 additions and 0 deletions

View File

@@ -109,9 +109,30 @@ sub delete {
return 0E0;
}
else {
# for node_ip and node_nbt *only* delete if there are no longer
# any active nodes referencing the IP or NBT (hence 2nd IN clause).
foreach my $set (qw/
NodeIp
NodeNbt
/) {
$schema->resultset($set)->search({
'-and' => [
'me.mac' => { '-in' => $nodes->as_query },
'me.mac' => { '-in' => $schema->resultset($set)->search({
-bool => 'nodes.active',
},
{
columns => 'mac',
join => 'nodes',
group_by => 'me.mac',
having => \[ 'count(nodes.mac) = 0' ],
})->as_query,
},
],
})->delete;
}
foreach my $set (qw/
NodeMonitor
NodeWireless
/) {