FDB Tables improve performance (#15333)

* FDB Tables improve performance
Reduce unnecessary sql queries, by using a relationship
Cache vendor oui lookups

* Oui already "clean"

* Fix typo
This commit is contained in:
Tony Murray
2023-09-25 19:49:22 -05:00
committed by GitHub
parent 9b159f8646
commit c8041b6699
3 changed files with 42 additions and 57 deletions

View File

@@ -27,6 +27,7 @@ namespace LibreNMS\Util;
use App\Models\Device;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use LibreNMS\Config;
@@ -158,10 +159,12 @@ class Rewrite
{
$oui = substr($mac, 0, 6);
$results = DB::table('vendor_ouis')
->where('oui', 'like', "$oui%") // possible matches
->orderBy('oui', 'desc') // so we can check longer ones first if we have them
->pluck('vendor', 'oui');
$results = Cache::remember($oui, 21600, function () use ($oui) {
return DB::table('vendor_ouis')
->where('oui', 'like', "$oui%") // possible matches
->orderBy('oui', 'desc') // so we can check longer ones first if we have them
->pluck('vendor', 'oui');
});
if (count($results) == 1) {
return Arr::first($results);