fix(locationMap): prevent FHIR API crash on IRIS map dezoom#1197
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical performance issue where multiple users dezooming the IRIS map simultaneously would crash the FHIR API due to a "thundering herd" of concurrent requests. The fix implements debouncing, concurrency limiting, zoom-based query guards, and improved request lifecycle management.
Changes:
- Added debouncing (300ms) for map pan/zoom events to prevent API calls during rapid user interactions
- Implemented limited concurrency (max 3 simultaneous tile requests) to reduce backend load from ~24 parallel requests to batches of 3
- Added zoom threshold guard to skip IRIS fetching when zoomed out below minimum level, preventing expensive wide-area queries
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| src/components/Dashboard/Preview/LocationMap/utils.test.ts | Added unit tests for getColorPalette and colorize utility functions to ensure color mapping logic works correctly |
| src/components/Dashboard/Preview/LocationMap/index.tsx | Implemented core performance fixes: debouncing logic, concurrency control with batched tile fetching, zoom threshold checks, improved abort handling with refs, and state management for debounced bounds |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 3 commits
April 16, 2026 14:03
This fixes the thundering herd problem when multiple users dezoom the IRIS map simultaneously, which was crashing the FHIR API. Changes: - Add 300ms debounce on map pan/zoom events to reduce API call frequency - Limit concurrent tile fetch requests from 24 to 3 max - Add zoom threshold guard: skip IRIS fetch when zoomed out too far - Improve abort controller: cancel in-flight requests on new interactions - Reset debouncedBounds when cohortId changes - Add unit tests for utility functions (getColorPalette, colorize) Ref gestion-de-projet#3027
- Fix cohort change leaving map empty (HIGH) setDebouncedBounds(bounds) instead of null to trigger fetch - Unify zoom threshold constants to 10 (MEDIUM) Use MIN_ZOOM_FOR_IRIS_FETCH for both fetch gate and MapContainer minZoom - Handle axios CanceledError in catch block (LOW) axios.isCancel(error) check alongside AbortError - Clear loading state on real errors setDataLoading(false) after console.error Reviewed-by: Deep Code Review
- Clear debounce timer on cohortId change to prevent stale bounds - Use Math.max for minZoom threshold to ensure fetch threshold is respected - Improve AbortError detection with cross-browser DOMException check - Add explicit test for count=0 edge case
0ebd051 to
424b3a4
Compare
- Convert loadedBounds and currentZoom from state to refs to avoid unnecessary effect re-executions that partially defeat the debounce - Simplify abort detection via signal.aborted instead of axios.isCancel, removing the axios import coupling - Always reset dataLoading on abort for defensive safety
Replace vague assertions (toBeLessThanOrEqual, toBeGreaterThanOrEqual) with exact expected values for getColorPalette and colorize. Add coverage for parseShape edge cases (undefined, empty, multipolygon).
tfi90
approved these changes
Apr 16, 2026
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
Fixes a critical issue where zooming out on the IRIS map with multiple concurrent users crashes the FHIR API due to a "thundering herd" of parallel tile requests.
Problem
When users zoom out on the IRIS map, the component:
This causes FHIR API crashes under concurrent load.
Solution
Testing
Related