fix : use upsert with onConflict to handle race condition in streak freeze#832
fix : use upsert with onConflict to handle race condition in streak freeze#832tmdeveloper007 wants to merge 2 commits into
Conversation
|
@TESTPERSONAL is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
The upsert correctly eliminates the race condition, but removes the 409 response that clients relied on to detect 'already have an unused freeze'. Now both new and duplicate freezes return 200 — callers can no longer distinguish them. Add a flag to the response (e.g. { ...record, already_existed: boolean }) or restore the 409 for the duplicate case.
|
The upsert approach is correct for handling race conditions, but removing the 409 response removes user feedback. Issue: The previous code returned a helpful Please restore the 409 path. With upsert, you can check if the returned row's // After upsert succeeds, check if freeze already existed
if (!error && freeze) {
// upsert always succeeds — but if freeze_date already existed, it's a no-op update
// to distinguish: query streak_freezes for this user before upsert, or use insert + catch 23505
}The simplest approach is to keep |
|
Deployment failed with the following error: |
e523270 to
a572549
Compare
|
This pull request is fully up-to-date with the latest upstream merges, all review items are addressed, local tests are passing cleanly, and it is fully ready to be merged! 🚀 |
fix : use upsert with onConflict to handle race condition in streak freeze