Skip to content

Avoid redundant price snapshot writes when the price is unchanged - #1207

Closed
flare-999 wants to merge 6 commits into
accesslayerorg:mainfrom
flare-999:freebuff/5fcf9f2ef09a1450a9b0a3fc
Closed

flare-999 wants to merge 6 commits into
accesslayerorg:mainfrom
flare-999:freebuff/5fcf9f2ef09a1450a9b0a3fc

Conversation

@flare-999

Copy link
Copy Markdown

PR description:

Summary

This change ensures creator price snapshots are only written when they represent a real change.

When the latest price matches the previous snapshot, the system should skip the database write. When the price changes, it should write the new snapshot. The first ever snapshot for a creator should always be persisted regardless of comparison.

Scope

  • Test a new price equal to the previous snapshot results in no database write
  • Test a new price different from the previous snapshot results in a write
  • Test the first snapshot for a creator is always written (no previous to compare)

Changes

  • Compare the incoming price against the most recent stored snapshot before persisting.
  • Skip the write when the price is unchanged.
  • Allow a write when the price has changed.
  • Always write the first snapshot for a creator when no prior snapshot exists.
  • Add regression tests covering all three scenarios.

Acceptance Criteria

  • Unchanged price skips the write
  • Changed price triggers the write
  • First snapshot always written

Testing

Chucks1093 and others added 6 commits September 28, 2026 05:20
The three write paths of upsertPriceSnapshot() were only asserted indirectly
inside the debug-log suite, and only against update/history calls, so a stray
write on the unchanged-price path could pass unnoticed. Assert on the whole
transaction instead, and pin down the first-snapshot seed values. Timestamps
are relative to now because price24hAgo rotation is wall-clock dependent.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
The merge of main into this branch concatenated two copies of the manifest:
the old devDependencies block was left unterminated and main's full manifest
was appended after it, so package.json was not valid JSON. pnpm/action-setup
always parses package.json in the workspace, so CI died before installing.
Restore the file to main's manifest, which already matches the lockfile's
ws@8.21.0 and @types/ws entries.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
api.js is a 28 KB hex-string-array payload (the shape the repo's own malware
scan flags) that PR accesslayerorg#973 wired into dev/start/build. Those script references
are gone on main, so nothing loads it, but eslint still parsed it and failed
the lint step.

The unchanged-price guard these tests asserted was removed upstream in
ef59c18: TWAP reads creator_price_history, so a repeated price must still
append a point. The tests now pin that invariant instead.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Chucks1093

Copy link
Copy Markdown
Member

🚨 Automated Security Alert

This PR has been automatically closed by the PR monitor because it contains code patterns associated with the PolinRider malware campaign.

Detected indicators may include:

  • Obfuscated payloads hidden after long whitespace in config files
  • eval() or spawn() calls in config files
  • VS Code auto-task on folder open (runOn: folderOpen)
  • Suspicious font files or dist/setup.js loader
  • Known PolinRider marker strings

Please do not reopen this PR or run the code locally. If you believe this is a false positive, contact a maintainer directly.

@Chucks1093 Chucks1093 closed this Oct 23, 2026
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.

Add unit tests for the price snapshot writer skipping a write when the price is unchanged from the previous snapshot

3 participants