From e15c78e9506c75cd6e5e155e505da4867a8cf05c Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 26 Dec 2025 01:10:59 -0500 Subject: [PATCH] Backfill smart feed with posts when sparse --- src/components/Map/usePostsEngine.js | 31 ++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/components/Map/usePostsEngine.js b/src/components/Map/usePostsEngine.js index 596945a..52342a5 100644 --- a/src/components/Map/usePostsEngine.js +++ b/src/components/Map/usePostsEngine.js @@ -663,8 +663,10 @@ export function usePostsEngine({ username: username || undefined, }); const timeParam = timeFilter && timeFilter !== "PAST" ? timeFilter : undefined; - if (!hasPostsInRadius(newPosts, lat, lng, radiusKm)) { - newPosts = await fetchPosts({ + const smartCount = Array.isArray(newPosts) ? newPosts.length : 0; + const needFallback = smartCount < 12 || !hasPostsInRadius(newPosts, lat, lng, radiusKm); + if (needFallback) { + const fallbackPosts = await fetchPosts({ category: catCode || undefined, subCategory: subCatParam || undefined, time: timeParam, @@ -673,8 +675,8 @@ export function usePostsEngine({ radiusKm, limit: 120, }); - if ((!Array.isArray(newPosts) || newPosts.length === 0) && timeFilter !== "PAST") { - newPosts = await fetchPosts({ + if ((!Array.isArray(fallbackPosts) || fallbackPosts.length === 0) && timeFilter !== "PAST") { + const widenedPosts = await fetchPosts({ category: catCode || undefined, subCategory: subCatParam || undefined, time: "PAST", @@ -683,6 +685,27 @@ export function usePostsEngine({ radiusKm, limit: 120, }); + const merged = new Map(); + for (const p of (newPosts || [])) { + const key = getPostKey(p); + if (key) merged.set(key, p); + } + for (const p of (widenedPosts || [])) { + const key = getPostKey(p); + if (key && !merged.has(key)) merged.set(key, p); + } + newPosts = Array.from(merged.values()); + } else { + const merged = new Map(); + for (const p of (newPosts || [])) { + const key = getPostKey(p); + if (key) merged.set(key, p); + } + for (const p of (fallbackPosts || [])) { + const key = getPostKey(p); + if (key && !merged.has(key)) merged.set(key, p); + } + newPosts = Array.from(merged.values()); } }