Skip to content

feat(scoring): implement atomic recordEvent() ledger writer (#90) - #399

Open
lucky-pluton wants to merge 1 commit into
vicharanashala:mainfrom
lucky-pluton:fix/90-record-event-ledger-writer
Open

lucky-pluton wants to merge 1 commit into
vicharanashala:mainfrom
lucky-pluton:fix/90-record-event-ledger-writer

Conversation

@lucky-pluton

Copy link
Copy Markdown
Contributor

Closes #90 — Part of the #87 scoring-ledger epic.

TL;DR

Replaces lost-update read-modify-write patterns with a centralized
ecordEvent(userId, event)\ ledger writer that mutates user scores atomically using MongoDB \\ and \\ operators.

Changes

  • Add \server/lib/ledger.js: exports
    ecordEvent(userId, event)\ which looks up reward calculations from \scoring.js\ and executes atomic \ indOneAndUpdate\ updates.
  • Add \server/tests/ledger.test.js: unit tests verifying reward calculations, debit operations, and high-concurrency atomic execution (10 parallel requests without lost updates).

Verification


  • pm test\ in \server/: all tests passed (191 tests).

  • px vitest run tests/ledger.test.js: 4/4 tests passed including concurrency test.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

✅ Parikshak — all automated checks pass

This is Parikshak, an automated, comment-only check — it never closes or approves a PR. A human reviewer still makes the final call. See CONTRIBUTING.md for the full contribution rules.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scoring: implement atomic recordEvent() ledger writer

1 participant