Fix auto-retry and time filter pool clearing
- Fixed auto-retry: now retries if 0 posts in first 15s after page load - Fixed time filter: now clears post pool when timeHours changes - Removed buggy initialLoadRef-based retry that never triggered Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3ee536f24f
commit
1eaa2f0ac9
|
|
@ -427,6 +427,7 @@ export function usePostsEngine({
|
||||||
const searchResultsRef = useRef(false);
|
const searchResultsRef = useRef(false);
|
||||||
const replacePoolRef = useRef(false);
|
const replacePoolRef = useRef(false);
|
||||||
const retryRef = useRef({ key: "", count: 0, ts: 0 });
|
const retryRef = useRef({ key: "", count: 0, ts: 0 });
|
||||||
|
const pageLoadTimeRef = useRef(Date.now());
|
||||||
const abortControllerRef = useRef(null);
|
const abortControllerRef = useRef(null);
|
||||||
const prevContentFilterRef = useRef(contentFilter);
|
const prevContentFilterRef = useRef(contentFilter);
|
||||||
const [mapReady, setMapReady] = useState(false);
|
const [mapReady, setMapReady] = useState(false);
|
||||||
|
|
@ -1250,8 +1251,8 @@ export function usePostsEngine({
|
||||||
if (distKm > Math.max(50, radiusKm * 0.5)) {
|
if (distKm > Math.max(50, radiusKm * 0.5)) {
|
||||||
shouldClearPool = true;
|
shouldClearPool = true;
|
||||||
}
|
}
|
||||||
} else if (forceFetch || last.filterKey !== filterKey) {
|
} else if (forceFetch || last.filterKey !== filterKey || last.timeHours !== timeHours) {
|
||||||
// Filter changed or force fetch - clear pool
|
// Filter changed (including time filter) or force fetch - clear pool
|
||||||
shouldClearPool = true;
|
shouldClearPool = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1388,19 +1389,19 @@ export function usePostsEngine({
|
||||||
|
|
||||||
setLoadingPosts(false);
|
setLoadingPosts(false);
|
||||||
|
|
||||||
// Auto-retry if we got very few posts (network timing issue)
|
// Auto-retry if we got 0 posts in the first 15 seconds after page load
|
||||||
const MIN_EXPECTED_POSTS = 5;
|
|
||||||
const fetchedCount = Array.isArray(newPosts) ? newPosts.length : 0;
|
const fetchedCount = Array.isArray(newPosts) ? newPosts.length : 0;
|
||||||
if (fetchedCount < MIN_EXPECTED_POSTS && initialLoadRef.current) {
|
const timeSincePageLoad = Date.now() - pageLoadTimeRef.current;
|
||||||
const retryKey = `retry:${Math.round(lat * 100)}|${Math.round(lng * 100)}`;
|
if (fetchedCount === 0 && timeSincePageLoad < 15000) {
|
||||||
|
const retryKey = `empty:${Math.round(lat * 100)}|${Math.round(lng * 100)}|${filterKey}`;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (retryRef.current.key !== retryKey || now - retryRef.current.ts > 10000) {
|
if (retryRef.current.key !== retryKey || now - retryRef.current.ts > 8000) {
|
||||||
retryRef.current = { key: retryKey, count: 0, ts: now };
|
retryRef.current = { key: retryKey, count: 0, ts: now };
|
||||||
}
|
}
|
||||||
if (retryRef.current.count < 2) {
|
if (retryRef.current.count < 2) {
|
||||||
retryRef.current.count += 1;
|
retryRef.current.count += 1;
|
||||||
retryRef.current.ts = now;
|
retryRef.current.ts = now;
|
||||||
console.log(`[usePostsEngine] Low post count (${fetchedCount}), auto-retry #${retryRef.current.count}`);
|
console.log(`[usePostsEngine] Empty result, auto-retry #${retryRef.current.count} (page load ${Math.round(timeSincePageLoad/1000)}s ago)`);
|
||||||
if (delayedFetchRef.current) clearTimeout(delayedFetchRef.current);
|
if (delayedFetchRef.current) clearTimeout(delayedFetchRef.current);
|
||||||
delayedFetchRef.current = setTimeout(load, 800);
|
delayedFetchRef.current = setTimeout(load, 800);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue