Skip to content

Commit e24e89e

Browse files
authoredMar 10, 2025
Merge pull request #11986 from nanaya/es-index-message
Fix es document reindex output
2 parents 5b6c375 + 344d47f commit e24e89e

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed
 

Diff for: ‎app/Console/Commands/EsIndexDocuments.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,21 @@ private function indexGroup($name)
104104

105105
foreach ($types as $type) {
106106
$bar = $this->output->createProgressBar();
107+
$bar->setFormat(' %current% [%bar%] %message%');
107108

108109
$this->info("{$pretext} {$type} into {$indexName}");
109110

111+
$progressCallback = function ($progress, $message) use ($bar) {
112+
$bar->setMessage($message);
113+
$bar->setProgress($progress);
114+
};
110115
if (!$this->inplace && $type === $first) {
111116
// create new index if the first type for this index, otherwise
112117
// index in place.
113-
$type::esIndexIntoNew(Es::CHUNK_SIZE, $indexName, function ($progress) use ($bar) {
114-
$bar->setProgress($progress);
115-
});
118+
$type::esIndexIntoNew(Es::CHUNK_SIZE, $indexName, $progressCallback);
116119
} else {
117120
$options = ['index' => $indexName];
118-
$type::esReindexAll(Es::CHUNK_SIZE, 0, $options, function ($progress) use ($bar) {
119-
$bar->setProgress($progress);
120-
});
121+
$type::esReindexAll(Es::CHUNK_SIZE, 0, $options, $progressCallback);
121122
}
122123

123124
$bar->finish();

Diff for: ‎app/Console/Commands/EsIndexWiki.php

+3
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ private function reindex()
136136
$total = count($paths);
137137
$this->line("Total: {$total} documents");
138138
$bar = $this->output->createProgressBar($total);
139+
$bar->setFormat(' %current% [%bar%] %message%');
140+
$logger = fn ($message) => $bar->setMessage($message);
139141

140142
foreach ($paths as $path => $_inEs) {
141143
$pagePath = Page::parsePagePath($path);
142144
$page = new Page($pagePath['path'], $pagePath['locale']);
145+
$page->logger = $logger;
143146
$page->sync(true, $this->indexName);
144147

145148
if (!$page->isVisible()) {

Diff for: ‎app/Models/Traits/Es/BaseDbIndexable.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static function esReindexAll($batchSize = 1000, $fromId = 0, array $optio
4646

4747
$baseQuery = static::esIndexingQuery()->where($dummy->getKeyName(), '>', $fromId);
4848
$count = 0;
49+
$progress ??= fn ($count, $message) => \Log::info(static::class.' '.$message);
4950

5051
$baseQuery->chunkById($batchSize, function ($models) use ($options, &$count, $progress) {
5152
$actions = Es::generateBulkActions($models);
@@ -60,14 +61,12 @@ public static function esReindexAll($batchSize = 1000, $fromId = 0, array $optio
6061
$count += count($result['items']);
6162
}
6263

63-
Log::info(static::class." next: {$models->last()->getKey()}");
64-
if ($progress) {
65-
$progress($count);
66-
}
64+
$progress($count, "next: {$models->last()->getKey()}");
6765
});
6866

6967
$duration = time() - $startTime;
70-
Log::info(static::class." Indexed {$count} records in {$duration} s.");
68+
69+
$progress($count, $message = "Indexed {$count} records in {$duration} s.");
7170
}
7271

7372
/**

Diff for: ‎app/Models/Wiki/Page.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Carbon\Carbon;
2222
use Ds\Set;
2323
use Exception;
24-
use Log;
2524

2625
class Page implements WikiObject
2726
{
@@ -41,6 +40,7 @@ class Page implements WikiObject
4140
];
4241

4342
public $locale;
43+
public \Closure $logger;
4444
public $path;
4545
public $requestedLocale;
4646

@@ -459,6 +459,12 @@ public function title($withSubtitle = false)
459459

460460
private function log($action)
461461
{
462-
Log::info("wiki ({$action}): {$this->pagePath()}");
462+
$message = "wiki ({$action}): {$this->pagePath()}";
463+
464+
if (isset($this->logger)) {
465+
($this->logger)($message);
466+
} else {
467+
\Log::info($message);
468+
}
463469
}
464470
}

0 commit comments

Comments
 (0)