perf: paginate large JSON payloads in reports and admin-audit-log API routes (#670) - #1032
perf: paginate large JSON payloads in reports and admin-audit-log API routes (#670)#1032Richiey1 wants to merge 2 commits into
Conversation
Add fr and pt locales to routing configuration. Create translation files for French and Portuguese (copied from en as base). LanguageSwitcher automatically detects new locales from routing config. Closes Iris-IV#680
… routes (Iris-IV#670) - Add pagination (page/pageSize), status filtering, and sparse field selection to GET /api/reports - Add pagination (page/pageSize), adminAddress/action filtering, and sparse field selection to GET /api/admin-audit-log - Update client-side getAdminAuditLog to request paginated pages instead of fetching the full dataset - Return { items, total, page, pageSize, hasMore } envelope from both endpoints - Add unit tests covering pagination, filtering, sparse fieldsets, and pageSize clamping
|
@Richiey1 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! 🚀 |
|
Auto-review failed (API error). Leaving PR for human review. |
| @@ -0,0 +1,132 @@ | |||
| import { NextResponse } from "next/server"; | |||
| @@ -0,0 +1,112 @@ | |||
| import { NextResponse } from "next/server"; | |||
| if (apiEntries.length > 0) { | ||
| writeAllEntries(apiEntries); | ||
| return apiEntries.sort((a, b) => b.timestamp - a.timestamp).slice(0, Math.max(0, limit)); | ||
| const { entries, total, hasMore } = await readApiEntries(normalizedAddress, page, pageSize); |
davidmaronio
left a comment
There was a problem hiding this comment.
the pagination core here is solid: sensible defaults, MAX_PAGE_SIZE clamp, NaN handling in parsePage/parsePageSize, the optional fields projection is a nice touch, and you added tests for both routes. the admin-audit-log action filter is also a genuine improvement.
blockers:
- the PR contains messages/fr.json, messages/pt.json and src/i18n/routing.ts, which are #1028's changes (and those files are 100% untranslated english copies). they are unrelated to json pagination and will collide with #1028. please rebase onto main so the diff only contains the pagination work.
- src/app/api/reports/route.ts:60 the GET response shape changes from a plain array to
{ items, total, page, pageSize, hasMore }. i do not see the admin moderation UI consumer updated in this diff, so anything doing(await res.json()).filter(...)breaks at runtime. either update all consumers in this PR or keep the old shape when no page param is passed. - src/lib/adminLog.ts:121
page = Math.max(1, Math.ceil(limit / pageSize))withpageSize = min(100, limit)always evaluates to page 1 for any limit up to 100, and for limit > 100 it fetches a later page instead of the first N entries, which is wrong. you likely just want page 1 with pageSize = clamped limit. - src/lib/adminLog.ts:127
hasMoreis destructured but never used, drop it or surface it to callers. - the identical parsePage/parsePageSize/pickFields helpers are duplicated in both routes, consider extracting them to a shared lib module.
note on CI: the lint/typecheck failures reference files this PR does not touch (WalletContext.tsx parse errors), so most of the red is a stale base and the rebase in ask 1 should clear it.
|
following up: the branch hasn't changed since the review. it still contains messages/fr.json, messages/pt.json and src/i18n/routing.ts from #1028, and the response-shape and page-math items from the review are unaddressed. please rebase onto main and push the fixes so this can move. |
Closes #670
Summary
Certain API routes returned massive, unpaginated JSON payloads that consumed excessive memory on the client side. This PR adds pagination, filtering, and sparse field selection to the largest endpoints so clients only fetch the data they actually need.
What changed
GET /api/reportsnow supports:page/pageSizepagination (defaults: page=1, pageSize=20, max=100)statusfiltering (pending,reviewed, orall)fieldssparse field selection (comma-separated){ items, total, page, pageSize, hasMore }envelopeGET /api/admin-audit-lognow supports:page/pageSizepaginationadminAddressfiltering (existing, preserved)actionfiltering (new)fieldssparse field selection{ entries, total, page, pageSize, hasMore }envelopesrc/lib/adminLog.tsupdated to passpageandpageSizeto the API instead of fetching the entire dataset and slicing client-side.Tests
pageSizeclamping.Verification
npm run lint— no new warnings or errors introduced by this changenpm run typecheck— no new type errors in modified filesnpm run test -- --testPathPatterns="src/__tests__/app/api"— 12/12 tests pass