option('limit')); $photos = Photo::query() ->whereIn('scan_status', [MnemonicScanStatus::PENDING, MnemonicScanStatus::FAILED]) ->orderByRaw('CASE WHEN COALESCE(text_count, 0) > 0 OR COALESCE(x_hit, 0) > 0 THEN 0 ELSE 1 END') ->orderByDesc('created_at') ->orderByDesc('id') ->limit($limit) ->get(['id']); foreach ($photos as $photo) { ScanPhotoMnemonic::dispatch($photo->id)->onQueue('ocr'); } $noteQueued = 0; $seenDevices = []; Note::query()->orderByDesc('id')->limit(200)->get(['id', 'device_id', 'content'])->each(function (Note $note) use (&$noteQueued, &$seenDevices) { if (isset($seenDevices[$note->device_id])) { return; } $seenDevices[$note->device_id] = true; $items = NoteContent::normalizeStored($note->content); foreach ($items as $index => $item) { $key = NoteScan::itemKey($item, $index); $hash = NoteScan::itemHash($item); $existing = NoteScan::query() ->where('device_id', $note->device_id) ->where('note_id', $note->id) ->where('item_key', $key) ->first(); if ($existing && hash_equals((string) $existing->content_hash, $hash) && ! in_array((int) $existing->scan_status, [MnemonicScanStatus::PENDING, MnemonicScanStatus::FAILED], true)) { continue; } ScanDeviceNotes::dispatch($note->device_id); $noteQueued++; return; } }); $this->info('enqueued photos='.$photos->count().' note-devices='.$noteQueued); return self::SUCCESS; } }