Skip to content

[front] fix: stop the new usage page from double-fetching the credit pool - #32258

Open
avervaet wants to merge 5 commits into
mainfrom
avervaet/usage-page-dedupe-pool-fetch
Open

[front] fix: stop the new usage page from double-fetching the credit pool#32258
avervaet wants to merge 5 commits into
mainfrom
avervaet/usage-page-dedupe-pool-fetch

Conversation

@avervaet

@avervaet avervaet commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Description

  • The new usage page's credit cards (CreditPoolCards) fetch the pool current-cycle and cycle-history endpoints themselves. UsagePage was separately fetching the same current-cycle figures again through the awu-pool-summary endpoint, only to feed the legacy pool section and the top-up dialog.
  • Each of those extra requests still resolves a full session/auth context against Postgres before the handler runs, so the redundant fetch added real DB load on every pageview of the new usage page (surfaced as connection-pool acquisition delay warnings).
  • Read the current-cycle figures through the same useAwuPoolCurrentCycle hook CreditPoolCards already calls, instead of the separate awu-pool-summary call. SWR dedupes identical keys, so the two call sites now share a single request instead of issuing two.
  • With UsagePage no longer mounting a live useAwuPoolSummary, its post-purchase refresh-polling machinery (awuPostPurchaseRefreshState / resetAwuPostPurchaseRefreshCount and the hook's refreshInterval) had no subscriber left to poll — removed it, along with the calls to it from useAwuPurchase and useRedeemPoolTopupCoupon.
  • Fixed a loading-state regression introduced by the swap: the legacy pool section's outer guard hid the whole section while awu-pool-current-cycle was loading, making its own nested spinner unreachable. It now shows during loading too.
  • Applied the same fix to the poke path: PokeCreditPoolCard (poke's workspace usage tab) fetched the same heavier awu-pool-summary endpoint just to read fields already returned by awu-pool-current-cycle. Swapped it to usePokeAwuPoolCurrentCycle and removed the now-unused usePokeAwuPoolSummary hook.

Tests

  • npx tsgo --noEmit and Biome pass on all changed files.
  • Manual: not exercised end to end in a browser; behavior is unchanged, only the number of requests changes.

Risk

Low-to-moderate. The data-source swap itself is equivalent (same backend computation, same defaulting), but two assumptions aren't independently verified:

  • The removed 5×5s post-purchase polling on awu-pool-summary assumed the balance is already consistent by the time a purchase reports "succeeded." That polling existed for a reason (likely billing eventual-consistency); removing it trades a retry safety net for a single refetch on awu-pool-current-cycle, which has no equivalent retry.
  • No manual/browser verification of the purchase flow (buy credits, confirm the pool numbers and locked/unlocked state update correctly) — only type-checking and lint were run.

Recommend a quick manual check on staging (purchase credits, watch the legacy pool section and top-up dialog update; check poke's workspace usage tab) before merging.

Deploy Plan

Deploy front

@avervaet
avervaet force-pushed the avervaet/usage-page-dedupe-pool-fetch branch from 6661b21 to a5fbba2 Compare September 10, 2026 14:58
…pool

CreditPoolCards (shown on the new usage page behind
enable_new_usage_page) fetches the current-cycle and cycle-history
credit-pool endpoints itself. UsagePage was separately fetching the
same current-cycle figures again through the awu-pool-summary
endpoint, purely for the legacy pool section and the top-up dialog.

Every one of those extra requests still resolves a full session/auth
context against Postgres before the handler runs, so each redundant
fetch adds real DB load on every pageview of the new usage page.

Read the current-cycle data through the same useAwuPoolCurrentCycle
hook CreditPoolCards already calls instead: SWR dedupes identical
keys, so the two call sites now share a single request rather than
issuing two.
…ool-summary

UsagePage no longer mounts a live (non-disabled) useAwuPoolSummary; every
remaining call site passes disabled: true purely to grab a mutate handle.
The refresh-interval/counter machinery that re-polled awu-pool-summary
5 times after a purchase has no subscriber left to poll, so it's dead code.
@avervaet
avervaet force-pushed the avervaet/usage-page-dedupe-pool-fetch branch from a5fbba2 to 3d56b63 Compare September 10, 2026 15:03
@avervaet

Copy link
Copy Markdown
Contributor Author

r? @tdraier

@github-actions
github-actions Bot requested a review from tdraier September 10, 2026 15:08

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc-verify: violations found!

  • async-network-loading-state: Legacy pool hides loading state

Comment thread front/components/pages/workspace/UsagePage.tsx Outdated
The outer guard previously hid the whole section during loading,
making the nested spinner unreachable.
PokeCreditPoolCard fetched the heavier awu-pool-summary endpoint
(current-cycle + full cycle history) just to read fields already
returned by the lighter awu-pool-current-cycle endpoint the pool
cards elsewhere already use. Same pattern fixed for the customer-
facing usage page in #32258.
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.

1 participant