Skip to content

[backend] fix(scenario): deletion take too long (#5208)#5932

Open
gabriel-peze wants to merge 3 commits into
mainfrom
fix/5208
Open

[backend] fix(scenario): deletion take too long (#5208)#5932
gabriel-peze wants to merge 3 commits into
mainfrom
fix/5208

Conversation

@gabriel-peze
Copy link
Copy Markdown
Contributor

Proposed changes

  • Implement bulk deletion on ES when a scenario is deleted

Testing Instructions

  1. Delete a scenario shoudn't take more than a few seconds

Related issues

@gabriel-peze gabriel-peze self-assigned this May 25, 2026
@gabriel-peze gabriel-peze added the filigran team use to identify PR from the Filigran team label May 25, 2026
@gabriel-peze gabriel-peze marked this pull request as ready for review May 26, 2026 15:27
Copilot AI review requested due to automatic review settings May 26, 2026 15:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 aims to reduce scenario (and related entity) deletion time by batching analytics-engine (Elasticsearch/OpenSearch) deletes and by pre-clearing inject dependency rows to avoid slow/erroneous cascade behavior during scenario removal.

Changes:

  • Batch DATA_DELETE index events per-transaction and flush once after commit (instead of one ES call per deleted entity).
  • Add a native bulk delete to clear injects_dependencies rows for a scenario prior to deleting the scenario.
  • Add unit tests validating the new EngineListener batching behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
openaev-model/src/main/java/io/openaev/engine/EngineListener.java Batch delete IDs during a transaction and flush once on afterCommit.
openaev-model/src/main/java/io/openaev/database/repository/InjectDependenciesRepository.java Add native bulk deletion of inject dependency rows by scenario id (tenant-scoped).
openaev-api/src/main/java/io/openaev/service/scenario/ScenarioService.java Call dependency cleanup before deleting a scenario (and wrap delete in a transaction).
openaev-api/src/main/java/io/openaev/rest/inject/service/InjectService.java Add service method delegating to the new bulk dependency delete repository method.
openaev-api/src/test/java/io/openaev/engine/EngineListenerTest.java New unit tests for batching/commit/rollback behavior.

Comment thread openaev-model/src/main/java/io/openaev/engine/EngineListener.java
Comment thread openaev-model/src/main/java/io/openaev/engine/EngineListener.java Outdated
Comment thread openaev-api/src/main/java/io/openaev/rest/inject/service/InjectService.java Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment on lines +329 to +332
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
public void clearInjectDependenciesByScenarioId(String scenarioId) {
injectDependenciesRepository.deleteAllByScenarioId(scenarioId);
}
Comment on lines 501 to 505
"""
// For each EsBase attribute of each document
for (String key : ctx._source.keySet().toArray()) {
// If it's a "base_XXX_side" (means String id or List of ids), we delete only in the "base_XXX_side" of the EsBase the object id deleted before with the deleteByQuery
// If it's a "base_XXX_side" (means String id or List of ids), remove all deleted ids from this field.
if(key.startsWith("base_") && key.endsWith("_side") && ctx._source[key] != null) {
Comment on lines 436 to 440
"""
// For each EsBase attribute of each document
for (String key : ctx._source.keySet().toArray()) {
// If it's a "base_XXX_side" (means String id or List of ids), we delete only in the "base_XXX_side" of the EsBase the object id deleted before with the deleteByQuery
// If it's a "base_XXX_side" (means String id or List of ids), remove all deleted ids from this field.
if(key.startsWith("base_") && key.endsWith("_side") && ctx._source[key] != null) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filigran team use to identify PR from the Filigran team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting any scenario or simulation takes a lot of time

3 participants