fix: never serve Accounts API balances from cache - #9867
Conversation
AccountsApiDataSource now invalidates cached balance queries before every fetch and fetches v5/v6 balances with staleTime: 0, gcTime: 0, so balances always hit the network in every flow (polling, forced refresh, websocket-triggered) and are never retained for reuse. Previously non-forced polls could reuse balances cached for up to 60s and forceUpdate: true only shrank the cache window to 100ms, so pull-to-refresh and post-transaction refreshes could show stale balances.
| // 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 }; |
There was a problem hiding this comment.
passing this to 0 now , we can also consider removing it
There was a problem hiding this comment.
Reverts this PR:
#9591
Worth double checking - I think instead of caching, we should attempt debouncing. But open to discuss
| // 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, 100% agreed here
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Align with MetaMask/core#9867: invalidate balance queries and fetch with staleTime/gcTime 0 on every AccountsApiDataSource fetch.
Align with MetaMask/core#9867: invalidate balance queries and fetch with staleTime/gcTime 0 on every AccountsApiDataSource fetch.
|
closing this one to do a revert instead: #9870 |
AccountsApiDataSource now invalidates cached balance queries before every fetch and fetches v5/v6 balances with staleTime: 0, gcTime: 0, so balances always hit the network in every flow (polling, forced refresh, websocket-triggered) and are never retained for reuse. Previously non-forced polls could reuse balances cached for up to 60s and forceUpdate: true only shrank the cache window to 100ms, so pull-to-refresh and post-transaction refreshes could show stale balances.
Extension PR: MetaMask/metamask-extension#45494
Mobile PR: MetaMask/metamask-mobile#34748
Explanation
References
Checklist