More changes to scanall to address memory issues

This commit is contained in:
Deon George 2024-09-18 11:36:42 +10:00
parent a6796a24ae
commit 59925f3af9
2 changed files with 44 additions and 28 deletions

View File

@ -46,6 +46,10 @@ class CatalogScanAll extends Command
$started = Carbon::now(); $started = Carbon::now();
$class = $this->getModelType($this->argument('type')); $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('')); Log::info('Scanning disk: '.Storage::disk('nas')->path(''));
$c = 0; $c = 0;
@ -73,38 +77,21 @@ class CatalogScanAll extends Command
} }
foreach ($list as $o) { foreach ($list as $o) {
// Check the details are valid if ($o->flag) {
if ($o->file_signature === $o->getObjectOriginal('file_signature')) { $o->scanned = FALSE;
// For sanity, we'll check a couple of other attrs $o->flag = FALSE;
if (($o->width !== $o->getObjectOriginal('width')) || ($o->height !== $o->getObjectOriginal('height'))) { $o->touch();
Log::alert(sprintf('Dimensions [%s] (%s x %s) mismatch for [%s]',
$o->dimensions,
$o->getObjectOriginal('width'),
$o->getObjectOriginal('height'),
$o->file_name(FALSE)));
$c++; if ($this->option('scan')) {
continue; Log::info(sprintf('Forcing re-scan of [%s] - queued',$o->filename));
CatalogScan::dispatch($o)
->onQueue('scan');
} }
} else { } else {
Log::alert(sprintf('File Signature [%s] doesnt match [%s] for [%s]', $o->flag = FALSE;
$o->getObjectOriginal('file_signature'), $o->touch();
$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');
} }
$c++; $c++;

View File

@ -59,6 +59,35 @@ class CatalogScan implements ShouldQueue, ShouldBeUnique
return; 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(); $this->o->init();
// If this is a duplicate // If this is a duplicate