fix(db): implement proposed conflict handling#21
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe update modifies the logic for inserting encrypted indicators into a database by introducing an upsert operation. Now, when a primary key conflict occurs during insertion, the ciphertext field is updated using the new value, streamlining conflict handling. The change also removes a previous comment regarding primary-key clashes. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Node
participant Database
Caller->>Node: add_or_increment_indicator(id, ciphertext)
Node->>Database: INSERT indicator (id, ciphertext) ON CONFLICT (id) DO UPDATE SET ciphertext = excluded.ciphertext
Database-->>Node: Success/Conflict handled
Node-->>Caller: Result
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|

TL;DR
Implement upsert functionality for threat indicators to handle duplicate submissions gracefully.
What changed?
diesel::upsert::excludedimport to support upsert operationsON CONFLICT DO UPDATEpattern in theadd_indicatormethod to handle primary key conflictsHow to test?
Why make this change?
This change prevents API 500 errors when legitimate duplicate indicators are submitted. Previously, submitting the same indicator twice would violate the primary key constraint and cause an error. Now, the system gracefully handles duplicates by updating the existing record, providing a more robust and user-friendly experience.
Summary by CodeRabbit