fix(db): upsert_client_sync: use ON CONFLICT DO UPDATE instead of INSERT OR REPLACE#6
Open
fix(db): upsert_client_sync: use ON CONFLICT DO UPDATE instead of INSERT OR REPLACE#6
Conversation
…ERT OR REPLACE
INSERT OR REPLACE is not a true upsert — SQLite deletes the conflicting row
and inserts a brand-new one, resetting every column that was not supplied to
its default value.
The most visible consequence: add_post() calls
upsert_client_sync(sync_since=X, last_activity=Y)
to prevent echoing a message back to its author. Under the old code this also
silently zeroed push_failures for that client, defeating the push-failure
circuit breaker that is supposed to evict unreachable clients after
MAX_PUSH_FAILURES consecutive failures.
Fix: switch to INSERT … ON CONFLICT(room_hash, client_pubkey) DO UPDATE SET
<only caller-supplied columns>. The INSERT path still supplies full defaults
for new rows; the UPDATE path only modifies what the caller explicitly passed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6630c19 to
1beb5bc
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
INSERT OR REPLACEdeletes and re-inserts the row, resetting any columns not included in the statementINSERT ... ON CONFLICT DO UPDATE SET ...to safely update only the specified columnsTest plan