Skip to content

fix(likes): count unique visitors and sync denormalized counter#96

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-bc6d
Draft

fix(likes): count unique visitors and sync denormalized counter#96
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-bc6d

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented May 27, 2026

Bug and impact

Recent denormalized like counts (PR #85) could show inflated or deflated totals when parallel setLike calls left duplicate likes rows for the same visitor, or when dedup deleted extra rows while decrementing a counter that never reflected those rows. One visitor rapid-clicking could move the public count by more than ±1.

Root cause

  • readLikeCount (pre-backfill) and backfill used row count instead of distinct ipHash
  • Dedup in setLike called decrementLikeCount per removed duplicate, desyncing likeCounts from reality
  • Increment/decrement deltas raced under concurrent mutations

Fix

Cherry-pick of d6e92c1 (already validated on cursor/critical-correctness-bugs-605e):

  • Count unique visitors via uniqueLikeCount
  • After every setLike, syncLikeCountForUrl sets the denormalized counter from source rows (also runs on idempotent retries, healing drift)
  • Backfill rebuilds per-URL totals from unique visitors, not per-row increments
  • Adds scripts/like-unique-count-test.mjs (12 parallel toggles; global count must move ≤1)

Validation

  • Cherry-pick applied cleanly on cursor/critical-bug-investigation-bc6d
  • Logic review of setLike / readLikeCount / backfill paths
  • Integration test script added (requires live dev server + Convex to run)
Open in Web View Automation 

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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Error Error May 27, 2026 3:08pm

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying web with  Cloudflare Pages  Cloudflare Pages

Latest commit: b2dc165
Status:🚫  Build failed.

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant