option('force'); $limitOption = $this->option('limit'); $limit = is_numeric($limitOption) ? (int) $limitOption : null; $query = Article::query()->orderBy('id'); if (! $force) { $query->whereDoesntHave('chunks'); } $total = (clone $query)->count(); if ($limit !== null && $limit > 0) { $total = min($total, $limit); } if ($total === 0) { $this->info('No articles to process.'); return self::SUCCESS; } $bar = $this->output->createProgressBar($total); $bar->start(); $processed = 0; $updated = 0; $failed = 0; $query->chunkById(50, function ($articles) use ($indexingService, $limit, &$processed, &$updated, &$failed, $bar) { foreach ($articles as $article) { if ($limit !== null && $processed >= $limit) { return false; } $processed++; try { $indexingService->indexArticle($article); $updated++; } catch (\Throwable) { $failed++; } $bar->advance(); } }); $bar->finish(); $this->newLine(2); $this->table(['Metric', 'Value'], [ ['Processed', $processed], ['Updated', $updated], ['Failed', $failed], ]); return self::SUCCESS; } }