Backfill smart feed with posts when sparse
This commit is contained in:
parent
5685668d18
commit
e15c78e950
|
|
@ -663,8 +663,10 @@ export function usePostsEngine({
|
||||||
username: username || undefined,
|
username: username || undefined,
|
||||||
});
|
});
|
||||||
const timeParam = timeFilter && timeFilter !== "PAST" ? timeFilter : undefined;
|
const timeParam = timeFilter && timeFilter !== "PAST" ? timeFilter : undefined;
|
||||||
if (!hasPostsInRadius(newPosts, lat, lng, radiusKm)) {
|
const smartCount = Array.isArray(newPosts) ? newPosts.length : 0;
|
||||||
newPosts = await fetchPosts({
|
const needFallback = smartCount < 12 || !hasPostsInRadius(newPosts, lat, lng, radiusKm);
|
||||||
|
if (needFallback) {
|
||||||
|
const fallbackPosts = await fetchPosts({
|
||||||
category: catCode || undefined,
|
category: catCode || undefined,
|
||||||
subCategory: subCatParam || undefined,
|
subCategory: subCatParam || undefined,
|
||||||
time: timeParam,
|
time: timeParam,
|
||||||
|
|
@ -673,8 +675,8 @@ export function usePostsEngine({
|
||||||
radiusKm,
|
radiusKm,
|
||||||
limit: 120,
|
limit: 120,
|
||||||
});
|
});
|
||||||
if ((!Array.isArray(newPosts) || newPosts.length === 0) && timeFilter !== "PAST") {
|
if ((!Array.isArray(fallbackPosts) || fallbackPosts.length === 0) && timeFilter !== "PAST") {
|
||||||
newPosts = await fetchPosts({
|
const widenedPosts = await fetchPosts({
|
||||||
category: catCode || undefined,
|
category: catCode || undefined,
|
||||||
subCategory: subCatParam || undefined,
|
subCategory: subCatParam || undefined,
|
||||||
time: "PAST",
|
time: "PAST",
|
||||||
|
|
@ -683,6 +685,27 @@ export function usePostsEngine({
|
||||||
radiusKm,
|
radiusKm,
|
||||||
limit: 120,
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue