Skip to content

Commit a3c286a

Browse files
committed
fix: some polish for indexing task, only re-indexing of a specific subclass of a index
1 parent 2658ce0 commit a3c286a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Tasks/AlgoliaReindex.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,34 @@ public function run($request)
7777

7878
// find all classes we have to index and do so
7979
foreach ($algoliaService->indexes as $indexName => $index) {
80-
echo 'Updating index ' . $indexName . PHP_EOL;
80+
$environmentizedIndexName = $algoliaService->environmentizeIndex($indexName);
81+
82+
echo 'Updating index ' . $environmentizedIndexName . PHP_EOL;
8183

8284
$classes = (isset($index['includeClasses'])) ? $index['includeClasses'] : null;
8385
$indexFilters = (isset($index['includeFilter'])) ? $index['includeFilter'] : [];
8486

8587
if ($classes) {
8688
foreach ($classes as $candidate) {
8789
if ($targetClass && $targetClass !== $candidate) {
88-
continue;
90+
// check to see if target class is a subclass of the candidate
91+
if (!is_subclass_of($targetClass, $candidate)) {
92+
continue;
93+
} else {
94+
$candidate = $targetClass;
95+
}
8996
}
9097

9198

9299
$items = $this->getItems($candidate, $filter, $indexFilters);
100+
101+
$filterLabel = implode(',', array_filter(array_merge([$filter], [$indexFilters[$candidate] ?? ''])));
102+
93103
echo sprintf(
94-
'| Found %s %s remaining to index which match filter (%s)%s',
104+
'| Found %s %s remaining to index %s%s',
95105
$items->count(),
96106
$candidate,
97-
implode(',', array_merge([$filter], [$indexFilters[$candidate] ?? ''])),
107+
$filterLabel ? 'which match filters ' . $filterLabel : '',
98108
PHP_EOL
99109
);
100110

@@ -106,7 +116,7 @@ public function run($request)
106116
}
107117

108118

109-
echo 'Done';
119+
echo 'Done' . PHP_EOL;
110120
}
111121

112122

0 commit comments

Comments
 (0)