Description
This issue addresses identified performance bottlenecks in the Elevation Atlas, specifically "Large HTTP Payload" and "N+1 API Calls" to PDOK services.
Identified Problems
- Large HTTP Payload: The
/elevation route was sending full-resolution GeoJSON geometries for all farm fields, leading to slow resource loading.
- N+1 WMS API Calls: The WMS overview layer was making redundant requests for tiles at high zoom levels (13+), even though high-resolution COG data was already being displayed.
- Slow Index Retrieval: Fetching the AHN kaartblad index (~1MB) directly from PDOK on every client session was slow and prone to network latency.
Optimizations Implemented
1. Geometry Simplification (Payload Reduction)
Implemented turf.simplify in the server-side loader within fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.elevation.tsx.
- Field geometries are now simplified with a tolerance of
0.00001 before being sent to the client.
- This significantly reduces the vertex count and total payload size without visible loss of detail on the map.
2. Server-Side Caching for AHN Index
Created a managed server-side cache to improve reliability and speed.
- Cache Utility:
fdm-app/app/lib/ahn-cache.server.ts fetches and stores the AHN index in memory with a 24-hour TTL.
- Resource Route:
fdm-app/app/routes/resources.ahn-index.tsx serves the cached index to the frontend.
- Frontend Integration: Updated the atlas to fetch from
/resources/ahn-index, ensuring the heavy JSON is served from the local network/cache.
3. WMS Layer Constraints (N+1 Fix)
Optimized the MapLibre layer configuration to prevent redundant background requests.
- Restricted the WMS source and layer to zoom levels below 13.
- Added
maxzoom={13} to the WMS Source.
- This ensures that once the user zooms in enough to see high-detail COG tiles, the WMS requests (which were causing N+1 overhead) are completely stopped.
Description
This issue addresses identified performance bottlenecks in the Elevation Atlas, specifically "Large HTTP Payload" and "N+1 API Calls" to PDOK services.
Identified Problems
/elevationroute was sending full-resolution GeoJSON geometries for all farm fields, leading to slow resource loading.Optimizations Implemented
1. Geometry Simplification (Payload Reduction)
Implemented
turf.simplifyin the server-side loader withinfdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.elevation.tsx.0.00001before being sent to the client.2. Server-Side Caching for AHN Index
Created a managed server-side cache to improve reliability and speed.
fdm-app/app/lib/ahn-cache.server.tsfetches and stores the AHN index in memory with a 24-hour TTL.fdm-app/app/routes/resources.ahn-index.tsxserves the cached index to the frontend./resources/ahn-index, ensuring the heavy JSON is served from the local network/cache.3. WMS Layer Constraints (N+1 Fix)
Optimized the MapLibre layer configuration to prevent redundant background requests.
maxzoom={13}to the WMS Source.