Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cursor-based pagination on blocks endpoint #2060

Merged
merged 9 commits into from
Aug 27, 2024

Conversation

zone117x
Copy link
Member

@zone117x zone117x commented Aug 23, 2024

Closes #2043

Supports a new cursor query param. The offset param continues to work but with a max page limit. Page random-access is possible when using both together.

This approach is generalizable and should work with other listing endpoints like transactions in future PRs.

Example usage:

GET /extended/v2/blocks?limit=3

{
  limit: 3,
  offset: 0,
  total: 14,
  cursor: '0x0000000000000000000000000000000000000000000000000000000000000014',
  next_cursor: null,
  prev_cursor: '0x0000000000000000000000000000000000000000000000000000000000000011',
  results: [
   { height: 14, ... },
   { height: 13, ... },
   { height: 12, ... }
  ],
}

GET /extended/v2/blocks?limit=3&cursor=0x0000000000000000000000000000000000000000000000000000000000000011

{
  limit: 3,
  offset: 0,
  total: 14,
  cursor: '0x0000000000000000000000000000000000000000000000000000000000000011',
  next_cursor: '0x0000000000000000000000000000000000000000000000000000000000000014',
  prev_cursor: '0x0000000000000000000000000000000000000000000000000000000000000008',
  results: [
   { height: 11, ... },
   { height: 10, ... },
   { height: 9, ... }
  ],
}

GET /extended/v2/blocks?limit=3&cursor=0x0000000000000000000000000000000000000000000000000000000000000011&offset=2

{
  limit: 3,
  offset: 0,
  total: 14,
  cursor: '0x0000000000000000000000000000000000000000000000000000000000000009',
  next_cursor: '0x0000000000000000000000000000000000000000000000000000000000000012',
  prev_cursor: '0x0000000000000000000000000000000000000000000000000000000000000006',
  results: [
   { height: 9, ... },
   { height: 8, ... },
   { height: 7, ... }
  ],
}

GET /extended/v2/blocks?limit=3&cursor=0x0000000000000000000000000000000000000000000000000000000000000008&offset=-2

{
  limit: 3,
  offset: 0,
  total: 14,
  cursor: '0x0000000000000000000000000000000000000000000000000000000000000010',
  next_cursor: '0x0000000000000000000000000000000000000000000000000000000000000013',
  prev_cursor: '0x0000000000000000000000000000000000000000000000000000000000000007',
  results: [
   { height: 10, ... },
   { height: 9, ... },
   { height: 8, ... }
  ],
}

Copy link

github-actions bot commented Aug 23, 2024

Vercel deployment URL: https://stacks-blockchain-q866qi2h7-hirosystems.vercel.app 🚀

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

src/api/routes/v2/blocks.ts Outdated Show resolved Hide resolved
src/api/schemas/responses/responses.ts Outdated Show resolved Hide resolved
src/datastore/pg-store-v2.ts Outdated Show resolved Hide resolved
src/tests/block-tests.ts Show resolved Hide resolved
Copy link
Collaborator

@rafaelcr rafaelcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@zone117x zone117x merged commit bfdcce1 into develop Aug 27, 2024
27 checks passed
@zone117x zone117x deleted the feat/blocks-cursor-pagination branch August 27, 2024 08:11
blockstack-devops pushed a commit that referenced this pull request Aug 27, 2024
## [8.0.0-beta.6](v8.0.0-beta.5...v8.0.0-beta.6) (2024-08-27)

### ⚠ BREAKING CHANGES

* refactor from express to fastify (#2045)

### Features

* cursor-based pagination on blocks endpoint ([#2060](#2060)) ([bfdcce1](bfdcce1))
* export events tsv directly to postgres instance ([#2048](#2048)) ([f401a0f](f401a0f))
* export events tsv directly to postgres instance ([#2048](#2048)) ([#2058](#2058)) ([a1f5b12](a1f5b12))
* refactor from express to fastify ([#2045](#2045)) ([bd65fcf](bd65fcf)), closes [#2042](#2042)

### Bug Fixes

* index on `principal_stx_txs` table for faster `/v1/address/{addr}/transactions` lookups ([#2059](#2059)) ([ab64ab7](ab64ab7))
@blockstack-devops
Copy link

🎉 This PR is included in version 8.0.0-beta.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Aug 28, 2024
## [8.0.0](v7.14.1...v8.0.0) (2024-08-28)

### ⚠ BREAKING CHANGES

* refactor from express to fastify (#2045)
* refactor from Express to Fastify

### Features

* cursor-based pagination on blocks endpoint ([#2060](#2060)) ([bfdcce1](bfdcce1))
* export events tsv directly to postgres instance ([#2048](#2048)) ([f401a0f](f401a0f))
* refactor from Express to Fastify ([aa0e51e](aa0e51e)), closes [#2042](#2042)
* refactor from express to fastify ([#2045](#2045)) ([bd65fcf](bd65fcf)), closes [#2042](#2042)

### Bug Fixes

* missing event limit max overrides on a few endpoints ([4f70930](4f70930))
* pagination and query param parsing bugs ([a382d2b](a382d2b)), closes [#2042](#2042)
* perform status endpoint sql inside transactions ([b23445c](b23445c))
* tx event-limit default should be 100 ([32d0670](32d0670))
@blockstack-devops
Copy link

🎉 This PR is included in version 8.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Add cursor-based pagination on /blocks endpoint
3 participants