fix: --seed-missing stops early when a full range is already indexed
When all documents in a range were already in the index, the empty collection caused continueAt to be set to null, aborting before scanning lower ID ranges. Now advances past the range bottom instead.
This commit is contained in:
parent
6699c8cb58
commit
5929a191f6
|
|
@ -142,6 +142,9 @@ class BuildCommand extends Command
|
||||||
$seeded = null;
|
$seeded = null;
|
||||||
|
|
||||||
while ($continueAt !== null) {
|
while ($continueAt !== null) {
|
||||||
|
$rangeFrom = max(1, $continueAt - 1000);
|
||||||
|
$rangeTo = $continueAt;
|
||||||
|
|
||||||
if ($this->option('seed-missing')) {
|
if ($this->option('seed-missing')) {
|
||||||
$response = (new Builder($client))
|
$response = (new Builder($client))
|
||||||
->index($index)
|
->index($index)
|
||||||
|
|
@ -149,8 +152,8 @@ class BuildCommand extends Command
|
||||||
->addQuery(
|
->addQuery(
|
||||||
(new BoolQuery())
|
(new BoolQuery())
|
||||||
->add((new RangeQuery('rawId'))
|
->add((new RangeQuery('rawId'))
|
||||||
->gte($continueAt - 1000)
|
->gte($rangeFrom)
|
||||||
->lte($continueAt))
|
->lte($rangeTo))
|
||||||
->add(TermQuery::create('type', $seeder->type()))
|
->add(TermQuery::create('type', $seeder->type()))
|
||||||
)
|
)
|
||||||
->search();
|
->search();
|
||||||
|
|
@ -161,7 +164,7 @@ class BuildCommand extends Command
|
||||||
/** @var Collection $collection */
|
/** @var Collection $collection */
|
||||||
$collection = $seeder->query()
|
$collection = $seeder->query()
|
||||||
->latest('id')
|
->latest('id')
|
||||||
->whereBetween('id', [$continueAt - 1000, $continueAt])
|
->whereBetween('id', [$rangeFrom, $rangeTo])
|
||||||
->when($this->option('max-id'), function ($query, $id) {
|
->when($this->option('max-id'), function ($query, $id) {
|
||||||
$query->where('id', '<=', $id);
|
$query->where('id', '<=', $id);
|
||||||
})
|
})
|
||||||
|
|
@ -169,11 +172,19 @@ class BuildCommand extends Command
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$min = $collection->min('id');
|
$min = $collection->min('id');
|
||||||
|
|
||||||
|
if ($this->option('seed-missing') && $collection->isEmpty()) {
|
||||||
|
// All docs in this range are already indexed; advance past the range bottom.
|
||||||
|
$continueAt = $rangeFrom > 2 ? $rangeFrom - 1 : null;
|
||||||
|
} else {
|
||||||
$continueAt = $min && $min > 2 ? $min - 1 : null;
|
$continueAt = $min && $min > 2 ? $min - 1 : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($collection->isNotEmpty()) {
|
||||||
$queue->pushOn(Job::$onQueue, new SavingJob($collection, $seeder));
|
$queue->pushOn(Job::$onQueue, new SavingJob($collection, $seeder));
|
||||||
|
}
|
||||||
|
|
||||||
$this->info("Pushed into the index, type: {$seeder->type()}, amount: {$collection->count()}.");
|
$this->info("IDs {$rangeFrom}–{$rangeTo} | type: {$seeder->type()} | queued: {$collection->count()}.");
|
||||||
|
|
||||||
$total += $collection->count();
|
$total += $collection->count();
|
||||||
|
|
||||||
|
|
@ -188,7 +199,7 @@ class BuildCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info("Pushed a total of $total into the index.");
|
$this->info("Queued a total of $total {$seeder->type()} for indexing.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue