Skip to content

feat: add cursor-based pagination for messages and posts#282

Merged
odesenfans merged 2 commits into
mainfrom
od/cursor-based-pagination
Apr 9, 2026
Merged

feat: add cursor-based pagination for messages and posts#282
odesenfans merged 2 commits into
mainfrom
od/cursor-based-pagination

Conversation

@odesenfans
Copy link
Copy Markdown
Contributor

Summary

  • Add get_messages_cursor() and get_posts_cursor() methods using cursor-based pagination (no COUNT query, faster for large result sets)
  • Add CursorPaginationResponse, CursorPostsResponse, and CursorMessagesResponse response models
  • Update get_messages_iterator() and get_posts_iterator() to use cursor-based pagination, eliminating duplicate results
  • Client-side validation: rejects sortBy=tx-time with cursor mode, caps page size at 200

Test plan

  • Verify get_messages_cursor() and get_posts_cursor() return correct cursor-paginated responses
  • Verify iterators paginate through all results using cursor mode
  • Verify ValueError is raised when using sortBy=tx-time with cursor methods
  • Verify page size is capped at 200
  • Verify next_cursor=None correctly terminates iteration

Add get_messages_cursor() and get_posts_cursor() methods that use
cursor-based pagination (faster, no COUNT query). Update iterators
to use cursor mode by default, eliminating duplicate results.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

Failed to retrieve llama text: POST 502: Bad Gateway

Add stub implementations for get_posts_cursor and get_messages_cursor
to satisfy the abstract class contract.
@odesenfans odesenfans merged commit 6155684 into main Apr 9, 2026
37 checks passed
@odesenfans odesenfans deleted the od/cursor-based-pagination branch April 9, 2026 15:34
amalcaraz added a commit to aleph-im/aleph-nodestatus that referenced this pull request May 20, 2026
Offset pagination on /api/v0/messages.json was hitting aiohttp's 5-min
timeout before the first page returned for AGGREGATE+date-filtered
queries over multi-week windows. aleph-im/aleph-sdk-python#282 added
cursor-based pagination (`get_messages_cursor` / `get_posts_cursor`)
in 2.3.2+ — server-side it scans by sort key, not row offset, so deep
pages don't slow down. Adopt it.

Dep cascade required by aleph-sdk-python>=2.3.2:
  - python:           3.9-slim → 3.12-slim (3.9 EOL'd 2025-10; SDK
                                            2.3.2+ requires >=3.10)
  - aleph-sdk-python: 1.4.0    → 2.3.3
  - aleph-message:    0.5      → 1.1
  - aleph-superfluid: 0.2      → 0.3
  - pydantic:         1.10     → 2.13 (+ pydantic-settings 2.x for
                                       BaseSettings, now a separate pkg)
  - web3:             6.3      → 7.16
  - eth-account:                  ≥0.13

Migration touches:
  - settings.py:        BaseSettings import path, `@field_validator`
                        decorator, `SettingsConfigDict` for env_file,
                        type annotations on two previously bare fields.
  - erc20.py, sablier.py: drop dead imports of `geth_poa_middleware` and
                          `local_filter_middleware` (web3 7 removed both;
                          neither was used).
  - ethereum.py, payment_processor.py:
                        eth-account 0.13 renamed `signed.rawTransaction`
                        → `signed.raw_transaction`.
  - credit_distribution.py:
                        `_LoggingAlephHttpClient` now overrides
                        `get_messages_cursor` and `get_posts_cursor` for
                        per-cursor progress logs + timeout-aware error.
                        `_iter_messages_dedup` walks `next_cursor`
                        instead of `get_messages_iterator`; the JSONL
                        cache stores `model_dump(mode="json")` output
                        for json-safe round-trip.
                        `get_latest_successful_credit_distribution` walks
                        posts via `get_posts_cursor` too.

43/43 tests pass on the new stack. Docker image rebuilt and inspected
to confirm aleph-sdk-python 2.3.3 + pydantic 2.13 + web3 7.16 install
clean under python:3.12-slim.
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.

1 participant