Skip to content

feat: add getActivePiecesByCursor for gas-efficient pagination#246

Merged
rvagg merged 2 commits intoFilOzone:mainfrom
Chaitu-Tatipamula:fix/add-getActivesPiecesByCursor
Feb 3, 2026
Merged

feat: add getActivePiecesByCursor for gas-efficient pagination#246
rvagg merged 2 commits intoFilOzone:mainfrom
Chaitu-Tatipamula:fix/add-getActivesPiecesByCursor

Conversation

@Chaitu-Tatipamula
Copy link
Contributor

Summary

Fixes #243 - Adds getActivePiecesByCursor function that uses cursor-based pagination with O(limit) gas complexity, avoiding the gas exhaustion issue with getActivePieces at high offsets.

Changes

  • New function: getActivePiecesByCursor(setId, startPieceId, limit) - starts from startPieceId instead of scanning from 0
  • Updated docs: Added warning to getActivePieces about O(offset) gas complexity
  • Tests: Added 6 new tests covering basic pagination, deleted pieces, edge cases

Usage

// First page
(pieces, ids, hasMore) = getActivePiecesByCursor(setId, 0, 100);

// Next page: use last returned pieceId + 1
(pieces, ids, hasMore) = getActivePiecesByCursor(setId, ids[ids.length-1] + 1, 100);

Copy link
Contributor

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

Merging, but this isn't going live until we can schedule an upgrade

@rvagg rvagg merged commit 12a3799 into FilOzone:main Feb 3, 2026
3 checks passed
@github-project-automation github-project-automation bot moved this to 🎉 Done in PDP Feb 3, 2026
@rvagg
Copy link
Contributor

rvagg commented Feb 3, 2026

Thanks @Chaitu-Tatipamula, good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

getActivePieces runs out of gas with high offsets due to O(n) loop from index 0

2 participants