Adjust the stale and cacheTimes of useAvalancheCenterMetadata#1104
Merged
stevekuznetsov merged 1 commit intoNWACus:mainfrom Feb 23, 2026
Merged
Conversation
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.
This is an attempt at trying to fix
Every once and awhile we get alerts about avalanche centers not containing certain zones. This always seems to be an issue with the avalanche center metadata not containing the zone that it needs.
The 2 situations where I think this arises are:
The reason why this could happen is that when the user opens the app for the first time, the metadata for every single center is prefetched and held onto forever. This means that it's possible for ReactQuery to give us data from the cache that hasn't been updated in a really long time and for the map-layer call and the metadata for the center to be out of sync.
By updating
cacheTimehere to 1 day we're letting ReactQuery know that it's okay to garbage collect the data for the query after 1 day of inactivity.cacheTimeandstaleTimeare confusing and in TanStack Query (ReactQuery) v5 they actually renamedcacheTimetogcTime(garbage collection time) to more accurately reflect what it does.Quick Overview
staleTimecontrols the fetching strategy for the query call. The default is0which means that immediately after fetching the data is marked as stale. This does not impact keeping/removing data from the cache. What this does is let the query know that fresh data needs to be fetched in the background. It immediately serves the data in the cache from previous calls, if there already is data, and updates it in the background. By setting it to 1 day here we're telling ReactQuery to not make any more calls to refetch the data for 1 day.cacheTimeonly comes into play when a query has become inactive. This means that no views in the stack are currently relying on the data. While a query is active, the data is always cached. By setting it to 1 day here, we're letting ReactQuery know that it's safe to remove this data after 1 day of it not being used at all. It makes sense to me to remove data from centers that may never be shown. We refetch the data when the user is shown the Avalanche Center Selector at which point seeing a loading screen there is better than seeing "This zone doesn't exist"We might need to go through other areas of the app to see if
cacheTime: Infinityshould be removed in other areas. It could be leading to memory leak issues as we use it in a lot of queries