fix(likes): count unique visitors, not duplicate rows#89
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
Parallel setLike races could leave multiple likes rows for one ipHash. Reads used row count (and backfill incremented per row), inflating counts. Dedup decrements could also desync the denormalized counter. Count distinct ipHashes, sync the counter after each mutation, and rebuild backfill totals per URL from unique visitors. 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
setLikemutations could leave multiplelikesrows for the sameurl+ipHash. The public count used row count (likes.lengthand backfillincrementLikeCountper row), so one visitor could inflate the displayed total (e.g. 2–3×). Dedup logic also calleddecrementLikeCountper removed duplicate, which could desync the denormalized counter.Root cause
The denormalized likes work in #85 counted table rows instead of distinct visitors. The earlier race fix branch (
4a4e7fc) usedSet(ipHash)for reads; the counter migration regressed to row-based counting.Fix
ipHashper URL for pre-backfill reads (uniqueLikeCount)syncLikeCountForUrlafter eachsetLikeso the denormalized counter matches realityValidation
scripts/like-unique-count-test.mjs(parallel POSTs; global count must not move by more than 1 for one visitor)Note: Production may still show stale inflated counts until affected pages get a like toggle or an admin re-runs
backfill.run.