Skip to content

feat(search-index): add command to clean up unused indices#391

Open
cancan101 wants to merge 3 commits into
pimcore:2026.xfrom
cancan101:feature/cleaup
Open

feat(search-index): add command to clean up unused indices#391
cancan101 wants to merge 3 commits into
pimcore:2026.xfrom
cancan101:feature/cleaup

Conversation

@cancan101

Copy link
Copy Markdown
Contributor
  • 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

Changes in this pull request

Resolves #382

Additional info

- 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
@sonarqubecloud

sonarqubecloud Bot commented Feb 8, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-indices command with --dry-run mode.
  • Implemented UnusedIndexCleanupService to 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.

Comment on lines +34 to +39
public function __construct(
private readonly UnusedIndexCleanupService $unusedIndexCleanupService,
?string $name = null
) {
parent::__construct($name);
}
Comment thread src/Command/CleanupUnusedIndicesCommand.php Outdated
Comment thread src/Command/CleanupUnusedIndicesCommand.php
Comment on lines +74 to +80
$indexPrefix = $this->searchIndexConfigService->getIndexPrefix();

try {
$stats = $this->searchIndexService->getStats($indexPrefix . '*');
} catch (Exception) {
return [];
}
Comment thread src/Service/SearchIndex/UnusedIndexCleanupService.php
Comment on lines +184 to +190
### 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>
Comment thread src/Command/CleanupUnusedIndicesCommand.php
Co-authored-by: JiaJia Ji <kingjia90@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
2 New Major Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Duplicate Indices (even vs odd) - not cleaned up on reindex

4 participants