perf(invoice): fix broken pagination and inefficient status indexing#151
Open
Seunfunmi-319509 wants to merge 2 commits into
Open
Conversation
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
|
@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! 🚀 |
Author
|
please review |
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.
Summary
Fixes broken pagination in
get_by_statuscaused by dead index entries accumulating when invoices change status.Technical Explanation
When an invoice changes status,
move_status_indexremoves theStatusMembershipmarker but does not remove the entry from theStatusIndexEntrylist. Over time, the index fills with "dead" entries. Because pagination (offsetandlimit) was applied to the index array positions rather than the actual active members, a user could receive fewer thanlimitresults (or zero) even if many members exist — simply because the range contained only dead entries.Fix
Changed
get_by_statusto scan all index entries, count active members sequentially, and collect only those active members that fall within the requestedoffset..offset+limitrange. This ensures:get_by_statusreturns exactlylimititems if they exist, regardless of how many invoices have changed statusRelated Issue
Closes #140