Skip to content

perf(invoice): fix broken pagination and inefficient status indexing#151

Open
Seunfunmi-319509 wants to merge 2 commits into
TrusTrove:mainfrom
Seunfunmi-319509:perf/invoice-fix-pagination-status-indexing
Open

perf(invoice): fix broken pagination and inefficient status indexing#151
Seunfunmi-319509 wants to merge 2 commits into
TrusTrove:mainfrom
Seunfunmi-319509:perf/invoice-fix-pagination-status-indexing

Conversation

@Seunfunmi-319509

Copy link
Copy Markdown

Summary

Fixes broken pagination in get_by_status caused by dead index entries accumulating when invoices change status.

Technical Explanation

When an invoice changes status, move_status_index removes the StatusMembership marker but does not remove the entry from the StatusIndexEntry list. Over time, the index fills with "dead" entries. Because pagination (offset and limit) was applied to the index array positions rather than the actual active members, a user could receive fewer than limit results (or zero) even if many members exist — simply because the range contained only dead entries.

Fix

Changed get_by_status to scan all index entries, count active members sequentially, and collect only those active members that fall within the requested offset..offset+limit range. This ensures:

  • get_by_status returns exactly limit items if they exist, regardless of how many invoices have changed status
  • Pagination works correctly across multiple pages

Related Issue

Closes #140

The get_by_status function applied offset and limit to the raw
StatusIndexEntry array positions. When invoices change status,
move_status_index removes the StatusMembership marker but leaves
the entry in StatusIndexEntry. Over time, the index fills with
dead entries, causing pagination to return fewer than limit results.

Fix: track active members sequentially and apply pagination to them
rather than to index array positions. This ensures get_by_status
returns exactly limit items (if they exist) regardless of how many
invoices have changed status.

Closes TrusTrove#140
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Seunfunmi-319509 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! 🚀

Learn more about application limits

@Seunfunmi-319509

Copy link
Copy Markdown
Author

please review

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.

perf(invoice): fix broken pagination and inefficient status indexing

1 participant