fix(likes): dedupe parallel toggles to prevent count inflation and 500s#84
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(likes): dedupe parallel toggles to prevent count inflation and 500s#84cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Concurrent like POSTs could insert duplicate rows for the same url+ipHash. That inflated counts and made .unique() throw on the next toggle (500s). Collect rows instead of unique(), delete duplicate rows after each toggle, and count distinct ipHashes in aggregate so reads stay correct. Co-authored-by: Injoon Oh <injoon5@icloud.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Bug and impact
Parallel
POST /api/likesrequests (e.g. double-click) could both observe no existing row and insert duplicates for the sameurl+ipHash. That:countwasrows.length).unique()onby_url_ip, which throws when multiple rows exist → 500s and a broken like button for that visitor/pageSame class of race as the vote-count bug fixed in #71.
Root cause
likes.toggleused.unique()for read-modify-write without deduping duplicate rows created by overlapping mutations.Fix
by_url_iprows and delete extras before/after toggleipHashvalues per URL inaggregateso reads stay correct even if orphans existValidation
scripts/like-race-test.mjs(10 parallel toggles; fails if count jumps by >1)convex/lib/votes.js