fix: return total count from paginated list APIs for accurate pagination#2380
Open
octo-patch wants to merge 1 commit into
Open
fix: return total count from paginated list APIs for accurate pagination#2380octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
…ion (fixes songquanpeng#2338) The paginated list endpoints for channels, users, tokens, redemptions, and logs previously returned only the current page's data without a total count. The berry theme frontend inferred totals heuristically (data.length + 1 when the page was full), causing TablePagination to only display 2 navigable pages at a time -- users had to click next repeatedly to reach later pages. Changes: - Backend: add Count* functions in model layer (CountChannels, CountUsers, CountUserTokens, CountRedemptions, CountAllLogs, CountUserLogs) that perform a SELECT COUNT(*) with the same filters as the corresponding Get* functions. - Backend: update GetAll* controllers to run the count query and include a total field in the JSON response (backward-compatible; old clients ignore it). - Frontend (berry): store total count in dedicated state, pass it to the TablePagination count prop so all pages are immediately visible. Update onPaginationChange to fetch any not-yet-loaded page on direct navigation. Update search handlers to set count = data.length for search results.
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.
Fixes #2338
Problem
The paginated list endpoints for channels, users, tokens, redemptions, and logs returned only the current page's data without a total record count. The berry-theme frontend inferred the total heuristically:
This means that after loading the first page (e.g. 10 items), MUI
TablePaginationreceivedcount = 11, showing only 2 navigable pages at a time. Users had to click "Next" repeatedly to reach later pages — they could never jump directly to page 5 or the last page.Solution
Backend — Add
Count*functions in the model layer that execute aSELECT COUNT(*)with the same filter conditions as the correspondingGet*functions:model.CountChannels()model.CountUsers()model.CountUserTokens(userId)model.CountRedemptions()model.CountAllLogs(...)(respects all filter params)model.CountUserLogs(...)(respects all filter params)Each
GetAll*controller now runs the count query and includes atotalfield in the JSON response. This change is backward-compatible — old clients and other themes simply ignore the new field.Frontend (berry theme) — Each paginated list view:
totalfrom the API response in a dedicated state variable (channelCount,userCount, etc.)TablePagination'scountprop, making all pages visible immediatelyonPaginationChangeto fetch any not-yet-loaded page when the user navigates directly (e.g. jumps from page 1 to page 8)count = data.lengthfor search results (which are returned all at once)Testing
totalfield)