-
-
Notifications
You must be signed in to change notification settings - Fork 298
fix: never serve Accounts API balances from cache #9867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -427,9 +427,13 @@ export class AccountsApiDataSource extends AbstractDataSource< | |
| return response; | ||
| } | ||
|
|
||
| const fetchOptions = request.forceUpdate | ||
| ? { staleTime: 100, gcTime: 100 } | ||
| : undefined; | ||
| // Balances must never be served from the TanStack cache in any flow | ||
| // (polling, forced refresh, websocket-triggered): invalidate cached | ||
| // balance queries first (fetchQuery refetches invalidated queries | ||
| // regardless of freshness), then fetch with staleTime/gcTime 0 so the | ||
| // response is neither read back nor retained. | ||
| const fetchOptions = { staleTime: 0, gcTime: 0 }; | ||
| await this.#apiClient.accounts.invalidateBalances(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. staleTime/gcTime only apply to this one call, old entries in the shared cache keep their 60s freshness. Invalidating first marks them stale for all consumers and forces an unconditional refetch, guaranteeing balances never come from cache.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, 100% agreed here |
||
|
|
||
| // Feature-flagged: v6 endpoint with a fallback to legacy v5. The flag is | ||
| // read here (not cached) so a runtime toggle can revert v6 -> v5. | ||
|
|
@@ -482,13 +486,15 @@ export class AccountsApiDataSource extends AbstractDataSource< | |
| * Fetch balances from the legacy v5 endpoint and process them. | ||
| * | ||
| * @param accountIds - CAIP-10 account IDs to fetch balances for. | ||
| * @param fetchOptions - Cache/fetch options (e.g. force update settings). | ||
| * @param fetchOptions - No-cache fetch options (balances are never cached). | ||
| * @param fetchOptions.staleTime - Time in ms before cached data is stale. | ||
| * @param fetchOptions.gcTime - Time in ms before cached data is removed. | ||
| * @param request - The original data request containing accounts to map. | ||
| * @returns Unprocessed networks and processed asset balances by account. | ||
| */ | ||
| async #fetchV5Balances( | ||
| accountIds: string[], | ||
| fetchOptions: { staleTime: number; gcTime: number } | undefined, | ||
| fetchOptions: { staleTime: number; gcTime: number }, | ||
| request: DataRequest, | ||
| ): Promise<{ | ||
| unprocessedNetworks: string[]; | ||
|
|
@@ -519,13 +525,15 @@ export class AccountsApiDataSource extends AbstractDataSource< | |
| * Fetch balances from the v6 endpoint and process them. | ||
| * | ||
| * @param accountIds - CAIP-10 account IDs to fetch balances for. | ||
| * @param fetchOptions - Cache/fetch options (e.g. force update settings). | ||
| * @param fetchOptions - No-cache fetch options (balances are never cached). | ||
| * @param fetchOptions.staleTime - Time in ms before cached data is stale. | ||
| * @param fetchOptions.gcTime - Time in ms before cached data is removed. | ||
| * @param request - The original data request containing accounts to map. | ||
| * @returns Unprocessed networks and processed asset balances by account. | ||
| */ | ||
| async #fetchV6Balances( | ||
| accountIds: string[], | ||
| fetchOptions: { staleTime: number; gcTime: number } | undefined, | ||
| fetchOptions: { staleTime: number; gcTime: number }, | ||
| request: DataRequest, | ||
| ): Promise<{ | ||
| unprocessedNetworks: string[]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing this to 0 now , we can also consider removing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverts this PR:
#9591
Worth double checking - I think instead of caching, we should attempt debouncing. But open to discuss