onQueue($queue); } } public function handle(): void { $batch = max(1, min($this->batchSize, 1000)); $staleHours = max(0, $this->staleHours); $staleBefore = $staleHours > 0 ? now()->subHours($staleHours) : null; $query = Artwork::query() ->where('id', '>', $this->afterId) ->whereNotNull('hash') ->whereHas('embeddings') ->when($this->publicOnly, static fn ($query) => $query->public()->published()) ->orderBy('id') ->limit($batch); if ($staleBefore !== null) { $query->where(static function ($innerQuery) use ($staleBefore): void { $innerQuery->whereNull('last_vector_indexed_at') ->orWhere('last_vector_indexed_at', '<=', $staleBefore); }); } $artworks = $query->get(['id']); if ($artworks->isEmpty()) { return; } foreach ($artworks as $artwork) { SyncArtworkVectorIndexJob::dispatch((int) $artwork->id); } if ($artworks->count() === $batch) { $lastId = (int) $artworks->last()->id; self::dispatch($lastId, $batch, $this->publicOnly, $staleHours); } } }