weather: cache forecasts and cut redundant loads - #14
Open
dharmapoudel wants to merge 1 commit into
Open
dharmapoudel wants to merge 1 commit into
dharmapoudel wants to merge 1 commit into
Conversation
- Cache the forecast in localStorage for 15 minutes (the refresh cadence), keyed by rounded coords + units: warm starts paint instantly with no network, and moving to a new city or switching units refetches. Corrupt or unavailable storage degrades to the old behavior. - Background refreshes no longer flash "loading" every 15 minutes; a failed refresh keeps the stale data instead of swapping to the error screen (the next tick retries). - Only reload on `units`/`location` config changes instead of every config write, and dedupe concurrent loads so a config change racing the initial load shares one fetch.
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.
The weather app refetched open-meteo on every mount, every 15 minutes, and every config write -- flashing "loading weather..." each time and hitting the network even when nothing changed.
What this does
localStoragefor 15 minutes (the refresh cadence), keyed by rounded coords + units. Warm starts paint instantly with no network; driving to a new city or switching metric/imperial refetches. Corrupt or unavailable storage degrades to the old behavior.units/locationkeys instead of firing on every config write.Files
packages/webapps/catalog/weather/src/App.tsx--readForecastCache/writeForecastCachehelpers, cache lookup in the load path, in-flight dedupe, key-filteredonChanged.Validation
tsc --noEmitclean,vite buildclean.