Limit visible posts in map view
This commit is contained in:
parent
40b1924a77
commit
43fefaf235
|
|
@ -113,6 +113,9 @@ function getPostTimeMs(p) {
|
||||||
return d.getTime();
|
return d.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_POOL_POSTS = 150;
|
||||||
|
const MAX_VISIBLE_POSTS = 90;
|
||||||
|
|
||||||
function prunePosts(posts, center, maxCount) {
|
function prunePosts(posts, center, maxCount) {
|
||||||
if (!Array.isArray(posts) || posts.length <= maxCount) return posts || [];
|
if (!Array.isArray(posts) || posts.length <= maxCount) return posts || [];
|
||||||
const [centerLon, centerLat] = center || [];
|
const [centerLon, centerLat] = center || [];
|
||||||
|
|
@ -514,7 +517,12 @@ export function usePostsEngine({
|
||||||
(tf) => {
|
(tf) => {
|
||||||
const vAll = computeVisible(tf);
|
const vAll = computeVisible(tf);
|
||||||
const map = mapRef.current;
|
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
|
// reduce wall blink: don't update if same ids
|
||||||
setVisiblePosts((prev) => (sameIdList(prev, v) ? prev : v));
|
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 };
|
lastFetchRef.current = { center: [...resolvedView.center], radiusKm, filterKey, timeFilter, bounds };
|
||||||
|
|
||||||
// Smooth update: sync markers/clusters + wall without clearing everything
|
// Smooth update: sync markers/clusters + wall without clearing everything
|
||||||
|
|
@ -749,7 +757,7 @@ export function usePostsEngine({
|
||||||
});
|
});
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
const posts = Array.isArray(data?.posts) ? data.posts : [];
|
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);
|
refreshVisibleAndMarkers(timeFilter);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
@ -784,7 +792,7 @@ export function usePostsEngine({
|
||||||
}
|
}
|
||||||
const map = mapRef.current;
|
const map = mapRef.current;
|
||||||
const center = map?.getCenter?.();
|
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);
|
const catCode = categoryCode(mainFilter);
|
||||||
if (catCode) {
|
if (catCode) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue