Repository navigation
Conversation
Select the page of users first and restrict the balance and trade-count aggregates to it with a batched IN, so the listing no longer aggregates all transactions/trade_offers per request. Still two queries per page; response shape and pagination unchanged. Adds query-count regression tests. Closes arflexx#480 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XLxKZmAHvHzCQSoiPAXVMq
Author
|
Hi! Sorry for the timing — this PR went up a few hours after Wave 10 closed. The work was ready, but my build environment was down overnight and I missed the cutoff. Would you be open to rolling #480 over to the next Wave? Happy to address any review feedback in the meantime. |
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.
Description
Closes #480
GET /api/v1/admin/usersno longer issues per-user queries — the correlated subqueries were replaced by groupedLEFT JOINaggregates in #256 (97c848a). What remained was the other half of the problem described in this issue: each request still aggregated every row oftransactionsandtrade_offers, so latency and DB load kept growing with total platform activity even though only one page of users is returned.Change
server/src/routes/admin.ts— the page of users is selected first in apage_usersCTE, and both aggregates are restricted to that page with a batchedIN (SELECT id FROM page_users):transactions WHERE user_id IN (page)— uses the index ontransactions(user_id)(migration 010)trade_offers WHERE seller_id IN (page)UNION ALLbuyer_id IN (page)— uses the seller/buyer indexes (migration 010)Still exactly two queries per request (page + total count) regardless of page size. Response shape, ordering (
created_at DESC), and pagination metadata are unchanged.Verification
Equivalence and performance on real Postgres 16 (20k users, ~500k transactions, ~100k trade offers, with the migration-010 indexes): old and new queries return byte-identical results for pages
(limit, offset)= (20,0), (20,20), (50,0), (1,0), (7,13), (50,1000), (100,19950) and an out-of-range page.EXPLAIN ANALYZEfor a 20-user page: 312.7 ms → 7.9 ms.Tests (
server/src/routes/admin.test.ts, newdescribeblock):page,limit,total,totalPages) unchanged; users with no activity still get0[limit, offset]and scopes both aggregates topage_usersNote on CI
maincurrently failstsc --noEmitbecause ofsrc/services/notifications.ts/src/__tests__/notificationTemplates.test.ts(missingrenderTemplateexport, undefinedevent/payload/renderTradeDisputeOpened). That breaks compilation ofadmin.test.tsunder ts-jest onmaintoo, so I ran the admin suite with ts-jest diagnostics turned off. This PR adds no new type errors (tsc --noEmiterrors are all in those two notification files).Disclosure: I use AI assistance. I ran the tests and reviewed every change before submitting.