fix(data-api): port neuron_daily-history handlers to Postgres#4838
Merged
Conversation
Tier 2b of #4832: handleValidatorHistory, handleNeuronHistory, handleSubnetHistory, handleSubnetConcentrationHistory, handleSubnetPerformanceHistory, handleSubnetYieldHistory, handleChainTurnover, handleSubnetTurnover, and handleSubnetMovers were still D1-only. Adds the matching 9 routes to the data Worker and wires tryPostgresTier into each handler. The boundary-snapshot routes (chain/subnet turnover, movers) translate SQLite's date(MAX(snapshot_date), '-N days') to Postgres's native `MAX(snapshot_date) - N::int` (DATE arithmetic). snapshot_date is cast to ::text on every read since postgres.js parses DATE columns to JS Date objects by default, which would break the pure builders' string equality comparisons against D1's plain YYYY-MM-DD rows. validator_permit is BOOLEAN in Postgres (vs D1's 0/1 integer), so the two routes that SUM() it cast to ::int first (SUM(boolean) is a Postgres type error). Exports a few previously-private WINDOWS/DEFAULT_WINDOW constants and turnoverChangeDetail from src/concentration.mjs, subnet-performance.mjs, subnet-yield.mjs, and turnover.mjs so the Postgres routes can mirror their D1 siblings' window handling exactly. Refs #4832
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-data-api | 3e1887d | Commit Preview URL Branch Preview URL |
Jul 11 2026, 04:11 AM |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4838 +/- ##
==========================================
+ Coverage 97.76% 97.77% +0.01%
==========================================
Files 162 162
Lines 19038 19124 +86
Branches 7141 7185 +44
==========================================
+ Hits 18613 18699 +86
Misses 59 59
Partials 366 366
🚀 New features to boost your workflow:
|
Merged
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.
Summary
neuron_daily-derived handlers to the Postgres tier —handleValidatorHistory,handleNeuronHistory,handleSubnetHistory,handleSubnetConcentrationHistory,handleSubnetPerformanceHistory,handleSubnetYieldHistory,handleChainTurnover,handleSubnetTurnover,handleSubnetMovers.date(MAX(snapshot_date), '-N days')boundary-anchoring (used by chain/subnet turnover and movers) to Postgres's nativeMAX(snapshot_date) - N::intDATE arithmetic.snapshot_dateto::text— postgres.js parsesDATEcolumns to JSDateobjects by default, which would silently break the pure builders'row.snapshot_date === startDatestring-equality comparisons.validator_permitto::intin the twoSUM(validator_permit)aggregate queries — it'sBOOLEANin Postgres (vs D1's 0/1 integer), andSUM(boolean)is a Postgres type error.*_WINDOWS/DEFAULT_*_WINDOWconstants andturnoverChangeDetailfromsrc/concentration.mjs,src/subnet-performance.mjs,src/subnet-yield.mjs,src/turnover.mjsso the Postgres routes mirror their D1 siblings' window handling exactly.Test plan
npx vitest run tests/data-api.test.mjs tests/request-handlers-entities.test.mjs— 186 + 488 tests pass (21 new data-api route tests covering happy path + window-fallback + cold-store branches; 18 new entities wiring tests for postgres-wins/falls-back-to-D1)npx vitest run(full repo) — 259 files / 7369 tests passnpm run lint/npx prettier --checkon touched files — cleannpm run scan:public-safety— cleannpm run test:coverage+ manualcodecov/patch-style branch-coverage isolation on the diff (cross-referenced againstgit diff origin/main -U0added-line ranges) — every uncovered branch confirmed pre-existing/outside the patchThis closes out #4832's full scope (Tier 1a/1b/1c + Tier 2a/2b) — every D1-only handler flagged in the umbrella issue now has a Postgres tier with fallback.
Refs #4832