feat(search-index): add command to clean up unused indices#391
feat(search-index): add command to clean up unused indices#391cancan101 wants to merge 3 commits into
Conversation
- add generic-data-index:cleanup:unused-indices command - default behavior deletes unmanaged stale -odd/-even indices not referenced by aliases - add --dry-run option to preview deletions without changes - implement UnusedIndexCleanupService to detect candidates via prefix + alias diff - add unit tests for selection, dry-run, and execute behavior - document new cleanup command in index management docs
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new CLI command and supporting service to identify and remove stale Generic Data Index -odd/-even indices that are no longer referenced by any alias, addressing the duplicate-index buildup described in #382.
Changes:
- Added
generic-data-index:cleanup:unused-indicescommand with--dry-runmode. - Implemented
UnusedIndexCleanupServiceto compute unused managed indices via prefix filtering + alias diff and optionally delete them. - Added unit tests for selection logic and dry-run vs execute behavior; documented the new command.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
tests/Unit/Service/SearchIndex/UnusedIndexCleanupServiceTest.php |
Adds unit tests for unused-index discovery and dry-run/execute deletion behavior. |
src/Service/SearchIndex/UnusedIndexCleanupService.php |
Implements discovery and deletion of unused managed (-odd/-even) indices based on stats + alias list. |
src/Command/CleanupUnusedIndicesCommand.php |
Adds a new console command to run cleanup and optionally dry-run output. |
doc/02_Configuration/03_Index_Management.md |
Documents the new cleanup command and --dry-run option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function __construct( | ||
| private readonly UnusedIndexCleanupService $unusedIndexCleanupService, | ||
| ?string $name = null | ||
| ) { | ||
| parent::__construct($name); | ||
| } |
| $indexPrefix = $this->searchIndexConfigService->getIndexPrefix(); | ||
|
|
||
| try { | ||
| $stats = $this->searchIndexService->getStats($indexPrefix . '*'); | ||
| } catch (Exception) { | ||
| return []; | ||
| } |
| ### Cleaning Up Unused Indices | ||
|
|
||
| To clean up old indices that are not referenced by any alias, use the following command: | ||
|
|
||
| ``` | ||
| php bin/console generic-data-index:cleanup:unused-indices | ||
| ``` |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: JiaJia Ji <kingjia90@gmail.com>
|







Changes in this pull request
Resolves #382
Additional info