diff --git a/src/components/Map/usePostsEngine.js b/src/components/Map/usePostsEngine.js index 1608883..1027863 100644 --- a/src/components/Map/usePostsEngine.js +++ b/src/components/Map/usePostsEngine.js @@ -113,6 +113,9 @@ function getPostTimeMs(p) { return d.getTime(); } +const MAX_POOL_POSTS = 150; +const MAX_VISIBLE_POSTS = 90; + function prunePosts(posts, center, maxCount) { if (!Array.isArray(posts) || posts.length <= maxCount) return posts || []; const [centerLon, centerLat] = center || []; @@ -514,7 +517,12 @@ export function usePostsEngine({ (tf) => { const vAll = computeVisible(tf); const map = mapRef.current; - const v = filterByBounds(vAll, map); + const vBounded = filterByBounds(vAll, map); + let v = vBounded; + if (v.length > MAX_VISIBLE_POSTS) { + const center = map?.getCenter?.(); + v = prunePosts(v, [center?.lng, center?.lat], MAX_VISIBLE_POSTS); + } // reduce wall blink: don't update if same ids setVisiblePosts((prev) => (sameIdList(prev, v) ? prev : v)); @@ -689,7 +697,7 @@ export function usePostsEngine({ } } - allPostsRef.current = prunePosts(Array.from(byId.values()), [lng, lat], 180); + allPostsRef.current = prunePosts(Array.from(byId.values()), [lng, lat], MAX_POOL_POSTS); lastFetchRef.current = { center: [...resolvedView.center], radiusKm, filterKey, timeFilter, bounds }; // Smooth update: sync markers/clusters + wall without clearing everything @@ -749,7 +757,7 @@ export function usePostsEngine({ }); if (cancelled) return; const posts = Array.isArray(data?.posts) ? data.posts : []; - allPostsRef.current = prunePosts(posts, [lon, lat], 120); + allPostsRef.current = prunePosts(posts, [lon, lat], MAX_POOL_POSTS); refreshVisibleAndMarkers(timeFilter); } catch {} } @@ -784,7 +792,7 @@ export function usePostsEngine({ } const map = mapRef.current; const center = map?.getCenter?.(); - allPostsRef.current = prunePosts([p, ...allPostsRef.current], [center?.lng, center?.lat], 200); + allPostsRef.current = prunePosts([p, ...allPostsRef.current], [center?.lng, center?.lat], MAX_POOL_POSTS); const catCode = categoryCode(mainFilter); if (catCode) {