Paginate listing of registered recipients - #1341
Open
sunnykid-02 wants to merge 2 commits into
Open
sunnykid-02 wants to merge 2 commits into
sunnykid-02 wants to merge 2 commits into
Conversation
|
@sunnykid-02 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #1210
Close: #1210
What was implemented
lib.rs
— 3 changes
New constant MAX_PAGE_SIZE = 50 Caps the entries returned per call, preventing runaway ledger reads.
Two new StorageKey variants
NameIndex(u32), // position → name (dense array 0..RecipientCount)
NamePosition(String) // name → position (reverse lookup for O(1) remove)
3. register_recipient — appends to the index After writing the RecipientRecord, it now also writes:
NameIndex(count) → name
NamePosition(name) → count
4. remove_recipient — O(1) swap-remove Instead of just decrementing the counter, it now:
Looks up the removed name's position via NamePosition.
If not already the tail, copies the tail name into that slot and updates its NamePosition.
Removes the vacated tail slot and both NamePosition entries.
5. New entrypoint list_recipients(start, limit) → Vec
No auth required — pure view.
limit capped to MAX_PAGE_SIZE; limit = 0 also uses the cap.
Returns empty vec when start >= count.
Reads NameIndex(start)..NameIndex(end) sequentially.
test.rs
— 7 new tests
Test What it covers
list_recipients_empty Returns empty vec on fresh registry
list_recipients_single_page All names appear within one page
list_recipients_pagination Multi-page walk covers all entries, no duplicates
list_recipients_page_size_capped limit=1000 still returns at most MAX_PAGE_SIZE
list_recipients_start_beyond_count_returns_empty Out-of-range start returns empty
list_recipients_removed_names_absent Removed names don't appear after swap-remove
list_recipients_no_auth_required Works with env.set_auths(&[])
list_recipients_zero_limit_uses_cap limit=0 falls back to MAX_PAGE_SIZE