Optimize vulnerability synchronization logic to not perform redundant writes#4359
Merged
nscuro merged 2 commits intoDependencyTrack:masterfrom Nov 12, 2024
Merged
Conversation
This modification is in order to avoid multiple writes
and/or updates when there is no changes.
Part of the logic in updateVulnerability was optimized.
Add differ.applyIfChanged and callInTransaction.
SynchronizeVulnerability returns null if there is nothing
to synchronize.
Some modifications were needed to couple with new logic.
e.g. if (SynchronizeVulnerability = null) continue.
Test are provided.
Signed-off-by: Andres Tito <[email protected]>
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 |
nscuro
requested changes
Nov 10, 2024
src/main/java/org/dependencytrack/persistence/VulnerabilityQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/VulnerabilityQueryManager.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/persistence/VulnerabilityQueryManager.java
Outdated
Show resolved
Hide resolved
-Remove unnecesary persistance in updateVulnerability function. -Return updated exisitingVulnerability in updateVulnerability -Remove return of empty vulnerability -Wrap synchronizedVUlnerability in callInTransaction to share same transaction. Signed-off-by: Andres Tito <[email protected]>
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 modification is intended to avoid multiple updates/writes in the database when there are no changes. In general we want to reduce unnecessary load on the DB.
Part of the logic in updateVulnerability was optimized. The differ.applyIfChanged method was added, similar to what NIST is doing
dependency-track/src/main/java/org/dependencytrack/tasks/AbstractNistMirrorTask.java
Lines 222 to 257 in 8087a94
dependency-track/src/main/java/org/dependencytrack/persistence/NotificationQueryManager.java
Lines 162 to 171 in 7ce8e04
synchronizeVulnerability now returns null if there is nothing to synchronize.
Some modifications were needed to align with the new logic. For example:
if (synchronizeVulnerability == null) continue;Tests are provided.
Addressed Issue
Closes #3922
Additional Details
Checklist