From 59925f3af965ef341dfc56a3548a2ba4bf8c71c7 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 18 Sep 2024 11:36:42 +1000 Subject: [PATCH] More changes to scanall to address memory issues --- app/Console/Commands/CatalogScanAll.php | 43 +++++++++---------------- app/Jobs/CatalogScan.php | 29 +++++++++++++++++ 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/app/Console/Commands/CatalogScanAll.php b/app/Console/Commands/CatalogScanAll.php index 016b34f..267c52c 100644 --- a/app/Console/Commands/CatalogScanAll.php +++ b/app/Console/Commands/CatalogScanAll.php @@ -46,6 +46,10 @@ class CatalogScanAll extends Command $started = Carbon::now(); $class = $this->getModelType($this->argument('type')); + // Flag everything if we are forcing a rescan + if ($this->option('scan')) + $class::select('id')->update(['flag'=>TRUE]); + Log::info('Scanning disk: '.Storage::disk('nas')->path('')); $c = 0; @@ -73,38 +77,21 @@ class CatalogScanAll extends Command } foreach ($list as $o) { - // Check the details are valid - if ($o->file_signature === $o->getObjectOriginal('file_signature')) { - // For sanity, we'll check a couple of other attrs - if (($o->width !== $o->getObjectOriginal('width')) || ($o->height !== $o->getObjectOriginal('height'))) { - Log::alert(sprintf('Dimensions [%s] (%s x %s) mismatch for [%s]', - $o->dimensions, - $o->getObjectOriginal('width'), - $o->getObjectOriginal('height'), - $o->file_name(FALSE))); + if ($o->flag) { + $o->scanned = FALSE; + $o->flag = FALSE; + $o->touch(); - $c++; - continue; + if ($this->option('scan')) { + Log::info(sprintf('Forcing re-scan of [%s] - queued',$o->filename)); + + CatalogScan::dispatch($o) + ->onQueue('scan'); } } else { - Log::alert(sprintf('File Signature [%s] doesnt match [%s] for [%s]', - $o->getObjectOriginal('file_signature'), - $o->file_signature, - $o->file_name(FALSE))); - - $c++; - continue; - } - - $o->scanned = FALSE; - $o->touch(); - - if ($this->option('scan')) { - Log::info(sprintf('Forcing re-scan of [%s] - queued',$o->filename)); - - CatalogScan::dispatch($o) - ->onQueue('scan'); + $o->flag = FALSE; + $o->touch(); } $c++; diff --git a/app/Jobs/CatalogScan.php b/app/Jobs/CatalogScan.php index 86b6306..60391c0 100644 --- a/app/Jobs/CatalogScan.php +++ b/app/Jobs/CatalogScan.php @@ -59,6 +59,35 @@ class CatalogScan implements ShouldQueue, ShouldBeUnique return; } + // Check the details are valid + if ($this->o->file_signature === $this->o->getObjectOriginal('file_signature')) { + // For sanity, we'll check a couple of other attrs + if (($this->o->width !== $this->o->getObjectOriginal('width')) || ($this->o->height !== $this->o->getObjectOriginal('height'))) { + Log::alert(sprintf('Dimensions [%s] (%s x %s) mismatch for [%s]', + $this->o->dimensions, + $this->o->getObjectOriginal('width'), + $this->o->getObjectOriginal('height'), + $this->o->file_name(FALSE))); + + throw new \Exception(sprintf('Dimensions [%s] (%s x %s) mismatch for [%s]', + $this->o->dimensions, + $this->o->getObjectOriginal('width'), + $this->o->getObjectOriginal('height'), + $this->o->file_name(FALSE))); + } + + } else { + Log::alert(sprintf('File Signature [%s] doesnt match [%s] for [%s]', + $x=$this->o->getObjectOriginal('file_signature'), + $this->o->file_signature, + $this->o->file_name(FALSE))); + + throw new \Exception(sprintf('File Signature [%s] doesnt match [%s] for [%s]', + $x, + $this->o->file_signature, + $this->o->file_name(FALSE))); + } + $this->o->init(); // If this is a duplicate