From 724a05c44c712bbce67a46ac4c504d209783c30f Mon Sep 17 00:00:00 2001 From: Nick Hilliard Date: Wed, 5 Jan 2022 13:36:33 +0000 Subject: [PATCH] [IM] garbage collection for macaddress table --- app/Console/Commands/Utils/ExpungeLogs.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/Console/Commands/Utils/ExpungeLogs.php b/app/Console/Commands/Utils/ExpungeLogs.php index 45401cbc0..056012ac9 100644 --- a/app/Console/Commands/Utils/ExpungeLogs.php +++ b/app/Console/Commands/Utils/ExpungeLogs.php @@ -102,6 +102,33 @@ public function handle() ); $this->isVerbosityVerbose() && $this->info(' [done]' ); + // delete all learned mac address records which can't be linked to a vlaninterface + $this->isVerbosityVerbose() && $this->output->write('Expunging unused entries from macaddress database table...', false ); + DB::table('macaddress')->whereRaw( + 'id NOT IN ( + SELECT id FROM ( + SELECT m.id FROM macaddress AS m + INNER JOIN virtualinterface vi ON m.virtualinterfaceid = vi.id + INNER JOIN vlaninterface vli ON (vli.virtualinterfaceid = vi.id) + ) sq_hoodwink_sql + )' + )->delete(); + $this->isVerbosityVerbose() && $this->info(' [done]' ); + + // delete learned mac address records from deleted vlans + $this->isVerbosityVerbose() && $this->output->write('Expunging macaddress entries for unreferenced vlans...', false ); + DB::table('macaddress')->whereRaw( + 'id IN ( + SELECT id FROM ( + SELECT m.id FROM macaddress AS m + INNER JOIN virtualinterface vi ON m.virtualinterfaceid = vi.id + INNER JOIN vlaninterface vli ON (vli.virtualinterfaceid = vi.id) + WHERE vli.vlanid NOT IN (SELECT id FROM vlan) + ) sq_hoodwink_sql + )' + )->delete(); + $this->isVerbosityVerbose() && $this->info(' [done]' ); + return 0; } } \ No newline at end of file