feat: cache viewport bounds, debounce fetches, dedup polygons#58
Open
madhavcodez wants to merge 1 commit intomainfrom
Open
feat: cache viewport bounds, debounce fetches, dedup polygons#58madhavcodez wants to merge 1 commit intomainfrom
madhavcodez wants to merge 1 commit intomainfrom
Conversation
Add useBoundsCache (check, commit, reset) and useDebouncedCallback hooks. Dashboard now skips /locations fetches when the viewport sits inside a previously fetched region expanded 1.5x, debounces viewport changes to 300ms so fast panning collapses into a single request, and merges polygons into a Map keyed by id so redraws never flicker out already-visible buildings. The bounds cache only advances after a fetch succeeds, so aborted requests do not silently leave regions marked cached with no data. The polygon map is capped at 20,000 entries, trimmed to the most recent 15,000 when exceeded. Closes #56 Closes #43 Closes #54
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
What this does
Stops the dashboard from spamming the backend every time the map moves, and stops damage polygons from flickering in and out on each fetch.
Three mechanisms:
useBoundsCache) — tracks the union of regions already fetched. When the current viewport sits inside that cached region, no API call fires at all. When a fetch is needed, bounds expand by 1.5× so pre-loaded surroundings absorb small pans.useDebouncedCallback) — viewport changes are collapsed into a single fetch after 300ms of no movement, so rapid zig-zag panning doesn't produce 50 parallel requests.Mapkeyed by id, so new fetches never replace what's already drawn. No more flicker.Safety fixes
How to verify
DevTools → Network → filter
locations:Closes #56
Closes #43
Closes #54