Add /v1/project/batchDelete API method that deletes with SQL#4383
Merged
nscuro merged 9 commits intoDependencyTrack:masterfrom Dec 19, 2024
Merged
Add /v1/project/batchDelete API method that deletes with SQL#4383nscuro merged 9 commits intoDependencyTrack:masterfrom
nscuro merged 9 commits intoDependencyTrack:masterfrom
Conversation
Signed-off-by: Mikael Carneholm <mikael.carneholm.2@wirelesscar.com>
nscuro
requested changes
Nov 19, 2024
src/main/java/org/dependencytrack/resources/v1/ProjectResource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/resources/v1/ProjectResource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/resources/v1/ProjectResource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
Signed-off-by: Mikael Carneholm <mikael.carneholm.2@wirelesscar.com>
Signed-off-by: Mikael Carneholm <mikael.carneholm.2@wirelesscar.com>
Contributor
Author
|
@nscuro Am I expected to mark the conversations as resolved, or is there anything else blocking this PR from getting merged? |
nscuro
reviewed
Dec 17, 2024
nscuro
requested changes
Dec 17, 2024
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Outdated
Show resolved
Hide resolved
Use DbUtil to check DB type, use Project.id instead of uuid in queries and don't delete tags, notifications or policies. Signed-off-by: Mikael Carneholm <mikael.carneholm.2@wirelesscar.com>
nscuro
approved these changes
Dec 19, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This patch adds a /v1/project/batchDelete method that makes project life-cycle management more effective since multiple projects can be deleted per request.
Addressed Issue
This fixes #3361
Additional Details
This is a modified version of #3407 that instead uses pure SQL to do the deletion. And by doing so, it's much faster:
A caveat is that it uses SQL Common Table Expressions (CTEs) which are part of the ANSI standard since SQL:1999, but still not supported by all DB vendors. The H2 database used for the unit tests has experimental support for CTEs, but does not support CTE DELETE statements. For this reason the code checks the name of the JDBC driver to conditionally run certain statements if the driver is org.postgresql.Driver.
Benchmarks using a local sample DB populated with ~11000 projects imported from a production system:
NB: The effect of the batch size is limited by the checkpoint configuration (see https://www.enterprisedb.com/blog/basics-tuning-checkpoints), but in this test the container DB was running with a default configuration.
Checklist
- [ ] This PR fixes a defect, and I have provided tests to verify that the fix is effective- [ ] This PR introduces changes to the database model, and I have added corresponding update logic- [ ] This PR introduces new or alters existing behavior, and I have updated the documentation accordingly