perf(map): skip /info round-trip on small viewports + optimistic revalidate#50
Draft
jsenecal wants to merge 1 commit into
Draft
perf(map): skip /info round-trip on small viewports + optimistic revalidate#50jsenecal wants to merge 1 commit into
jsenecal wants to merge 1 commit into
Conversation
…lidate Panning and zooming used to block on a fresh /info round-trip before the GeoJSON layers could start loading. With ETag revalidation the gate returns 304 on most pans, but the round-trip itself is what was making the map feel laggy on slow links. The frontend now uses a three-band strategy (load-strategy.ts): zoom < MIN_DATA_ZOOM (11): render nothing. MIN_DATA_ZOOM <= zoom < SKIP_INFO_ZOOM (default 17): if a recent /info is cached, render that decision immediately and revalidate in the background with If-None-Match. A 304 leaves the screen untouched; a 200 reconciles only when the per-layer decision actually changes. First load with no cache still waits one round-trip. zoom >= SKIP_INFO_ZOOM: skip /info entirely. The viewport is too small to plausibly cross any hide/cluster threshold, so the gate is unhelpful. Configurable via PLUGINS_CONFIG['netbox_pathways']['map_skip_info_zoom'] if a deployment has unusual feature density. fetchMapInfo's callback now also signals whether the response was a 200 (fresh) or 304 (unchanged), so callers can skip the reconciliation render in the common case. The pure decision logic is covered by vitest (load-strategy.test.ts and fetch-info.test.ts, 15 new tests, 217/217 passing total).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #50 +/- ##
=======================================
Coverage 73.40% 73.40%
=======================================
Files 52 52
Lines 5189 5189
=======================================
Hits 3809 3809
Misses 1380 1380 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
/infobefore the GeoJSON layers start loading.SKIP_INFO_ZOOM(default 17)/infois skipped entirely -- the viewport is too small to plausibly cross any hide/cluster threshold./infodrives the immediate render and/inforevalidates in the background withIf-None-Match; a 304 leaves the screen untouched, a 200 reconciles only when the per-layer decision actually changes.PLUGINS_CONFIG['netbox_pathways']['map_skip_info_zoom']for deployments with unusual feature density.Changes
netbox_pathways/static/netbox_pathways/src/data-layers.ts:SKIP_INFO_ZOOM,decideSkipInfo,getLastInfo,_resetInfoCache;fetchMapInfocallback now(info, changed)so callers can skip re-render on 304.netbox_pathways/static/netbox_pathways/src/load-strategy.ts(new): exposeschooseLoadStrategy,decisionsDiffer, re-exportsdecideSkipInfo. Pure dispatch over (zoom,cachedInfo,enabled) ->{ below-min-zoom | skip-info | optimistic | gated }.netbox_pathways/static/netbox_pathways/src/pathways-map.ts:_loadData()is now a dispatch over the strategy result; only thegatedandoptimisticpaths touch/info.netbox_pathways/static/netbox_pathways/src/types/netbox.d.ts:PathwaysConfig.skipInfoZoom?: number.netbox_pathways/static/netbox_pathways/src/load-strategy.test.ts+src/fetch-info.test.ts(new): 15 vitest tests covering each strategy branch,decideSkipInfo,decisionsDiffer, and the(info, changed)callback contract.netbox_pathways/views.py: bothpathways_configbuilders (map + route planner) emitskipInfoZoom.netbox_pathways/template_content.py:LeafletHeadExtension.head()also includesskipInfoZoom, so detail-page maps see the configured value.[Unreleased]-> Added, new "How the gating performs during panning" section indocs/user-guide/interactive-map.md.Testing
vitestpasses (217 passed, 15 new)pytestpasses (456 passed)npm run buildclean (newdist/load-strategy.min.jsabout 1.3 KB)manage.py checkcleanwindow.PATHWAYS_CONFIGinjection points (head + body) emitskipInfoZoom: 17; minified bundle contains the new name and no staletrustZoom/TRUST_ZOOM.Notes
map_skip_info_zoomdescribes the mechanism). An earlier draft usedmap_trust_zoomwhich read like a security knob.