Skip to content

Commit

Permalink
[IM] garbage collection for macaddress table
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhilliard committed Jan 5, 2022
1 parent 53333e4 commit 724a05c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/Console/Commands/Utils/ExpungeLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 724a05c

Please sign in to comment.