fix(api): order /blocks by slot when slot-filtered; fix logger.warning crash - #1002
Merged
Conversation
…g crash Two production issues in the REST API: 1. GET /blocks with a slot range took ~9.5s and starved Prisma's connection pool. The query filtered on `slot` but ordered by `number`, so Postgres scanned the entire `number` index and discarded millions of out-of-range rows (EXPLAIN: block_number_idx scan, "Rows Removed by Filter: 2740916", 8.6s). Since `slot` and `number` are monotonically correlated, ordering by `slot` when a slot filter is present lets Postgres range-scan the `slot` index for both the predicate and the ordering. Verified: 8712ms -> 5.5ms, identical result order. 2. The Matomo middleware called logger.warning() on tracking failure, but the winston logger only defines warn(). This threw "logger.warning is not a function" as an unhandled promise rejection, crashing the API process (observed 684 restarts in production). Use logger.warn(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: ebe9261 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
📦 Next.js Bundle Analysis for @blobscan/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1002 +/- ##
==========================================
+ Coverage 83.46% 83.47% +0.01%
==========================================
Files 190 190
Lines 15081 15093 +12
Branches 1464 1466 +2
==========================================
+ Hits 12587 12599 +12
Misses 2494 2494 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Checklist
Description
Two production issues in the REST API:
GET /blocks with a slot range took ~9.5s and starved Prisma's connection pool. The query filtered on
slotbut ordered bynumber, so Postgres scanned the entirenumberindex and discarded millions of out-of-range rows (EXPLAIN: block_number_idx scan, "Rows Removed by Filter: 2740916", 8.6s). Sinceslotandnumberare monotonically correlated, ordering byslotwhen a slot filter is present lets Postgres range-scan theslotindex for both the predicate and the ordering. Verified: 8712ms -> 5.5ms, identical result order.The Matomo middleware called logger.warning() on tracking failure, but the winston logger only defines warn(). This threw "logger.warning is not a function" as an unhandled promise rejection, crashing the API process (observed 684 restarts in production). Use logger.warn().
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):