-
Notifications
You must be signed in to change notification settings - Fork 111
[backend] Added bulk create expectation traces endpoint #2945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/current
Are you sure you want to change the base?
Conversation
f74afd0
to
d9f5a74
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/current #2945 +/- ##
=====================================================
- Coverage 40.08% 39.98% -0.11%
- Complexity 2123 2173 +50
=====================================================
Files 646 652 +6
Lines 20024 20686 +662
Branches 1368 1493 +125
=====================================================
+ Hits 8027 8271 +244
- Misses 11556 11956 +400
- Partials 441 459 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d9f5a74
to
12e24ff
Compare
...as-api/src/main/java/io/openbas/rest/inject_expectation_trace/InjectExpectationTraceApi.java
Outdated
Show resolved
Hide resolved
...as-api/src/main/java/io/openbas/rest/inject_expectation_trace/InjectExpectationTraceApi.java
Outdated
Show resolved
Hide resolved
...main/java/io/openbas/rest/inject_expectation_trace/form/BulkInjectExpectationTraceInput.java
Outdated
Show resolved
Hide resolved
// Dedupe from DB | ||
List<SimpleRawExpectationTrace> rawsfromDB1 = | ||
this.injectExpectationTraceRepository.findAllTracesNewerThan( | ||
oldestAlertDate.get().truncatedTo(ChronoUnit.SECONDS)); | ||
Set<SimpleRawExpectationTrace> fromDB = new HashSet<>(rawsfromDB1); | ||
|
||
// Removing duplicate traces | ||
traces.keySet().removeAll(fromDB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you not better dedupe using the alert link which bears the alert id from the input object, and avoid all the timestamp black magic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to, but I don't think it's doable with correct performance. We can receive 10K+ inputs. Unless I'm missing something, what you suggest would require to either select with a 10K+ IN clause with alert links as a criteria, or make 10K+ different select calls to the DB.
Could you elaborate on your proposition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of something better than a custom insert query with the ON CONFLICT DO NOTHING clause from postgres https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
And the conflict would be on the alert_link column.
The JpaRepository does not expose this natively as it's a postgres feature (not standard SQL).
Here are examples as native queries:
- https://www.baeldung.com/spring-data-jpa-update-or-insert#3-using-database-built-in-feature
- https://www.baeldung.com/hibernate-insert-query-on-conflict-clause#2-do-nothing
Maybe worth a thought, especially if we're talking about five orders of magnitude?
The caveat here is that it would not account for alerts missing from subsequent batches (which would be deleted in the current code, not with the design discussed here).
Proposed changes
Related issues
Checklist