From 593b317d3025cc0ef019cc17740bd2d22e042819 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 1 Oct 2016 18:21:19 +0100 Subject: [PATCH] Avoid pathological delete mac for millions of nodes (S. Xu) --- Netdisco/Changes | 1 + .../lib/App/Netdisco/DB/ResultSet/Node.pm | 30 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index f692d51d..ed53c852 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -12,6 +12,7 @@ * [#279] Web sessions use cookies instead of files on disk (M. Johnson) * Strip realm from username (B. Marshall) * Mention netdisco-users mail list in docs (C. Goldsmith) + * Avoid pathological delete mac for millions of nodes (S. Xu) [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm index 4b9c4b5b..5c7e1920 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm @@ -115,21 +115,21 @@ sub delete { 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; + $schema->resultset($set)->search({ + 'me.mac' => { '-in' => $schema->resultset($set)->search({ + '-and' => [ + -bool => 'nodes.active', + 'me.mac' => { '-in' => $nodes->as_query } + ] + }, + { + columns => 'mac', + join => 'nodes', + group_by => 'me.mac', + having => \[ 'count(nodes.mac) = 0' ], + })->as_query, + }, + })->delete; } foreach my $set (qw/