Skip to content

fix(locationMap): prevent FHIR API crash on IRIS map dezoom#1197

Merged
tfi90 merged 6 commits into
developfrom
fix/iris-map-dezoom-crash
May 6, 2026
Merged

fix(locationMap): prevent FHIR API crash on IRIS map dezoom#1197
tfi90 merged 6 commits into
developfrom
fix/iris-map-dezoom-crash

Conversation

@gfortaine
Copy link
Copy Markdown
Contributor

@gfortaine gfortaine commented Jan 19, 2026

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:

  1. Fires 24+ parallel API requests simultaneously (one per visible tile)
  2. Each request can trigger heavy backend processing
  3. No debouncing - every zoom/pan event triggers immediate requests
  4. Abort controller only cancels on unmount, not on rapid zoom changes

This causes FHIR API crashes under concurrent load.

Solution

  1. Debouncing (300ms) - Prevents rapid-fire requests during zoom/pan
  2. Limited concurrency (3 parallel requests max) - Prevents API overload
  3. Zoom threshold (level 10+) - Only fetches data when zoomed in enough
  4. Improved abort handling - Cancels pending requests when view changes

Testing

  • Added unit tests for debouncing, concurrency limiting, and abort handling
  • Manual testing with rapid zoom operations

Related

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx
Comment thread src/components/Dashboard/Preview/LocationMap/utils.test.ts Outdated
Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx Outdated
Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx Outdated
Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx
Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx
Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx
Comment thread src/components/Dashboard/Preview/LocationMap/index.tsx
@cesar-richard cesar-richard reopened this Apr 16, 2026
Guillaume FORTAINE 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
@cesar-richard cesar-richard force-pushed the fix/iris-map-dezoom-crash branch from 0ebd051 to 424b3a4 Compare April 16, 2026 12:03
- 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).
@cesar-richard cesar-richard requested a review from tfi90 April 16, 2026 13:21
@cesar-richard cesar-richard self-assigned this Apr 16, 2026
@tfi90 tfi90 changed the base branch from main to develop May 6, 2026 11:49
@tfi90 tfi90 merged commit 6b4f309 into develop May 6, 2026
4 checks passed
@tfi90 tfi90 deleted the fix/iris-map-dezoom-crash branch May 6, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants