fix(feed): repair 2 bugs found in the Phase 2 #2 review

BUG-1 (search.py, high): the scrape search source logged one VIDEOS_SEARCH
quota event PER continuation page inside the paging loop, but actions_today
counts events — so a single user search that pages N times consumed N against
search_daily_limit_per_user (its docstring even warns it only works for
once-per-action logging). Log exactly once per request after the loop instead;
the API source already logs once via record_usage (it never auto-pages).

BUG-2 (Feed.tsx, medium): the optimistic-override reset effect keyed on
query.dataUpdatedAt also fired on fetchNextPage (infinite scroll bumps
dataUpdatedAt while page 1 is unchanged), so a just-hidden card flashed back
mid-scroll. Guard with a page-count ref: only reset on a real refetch, not an
append. The two override-reset effects legitimately differ now (resolves the
would-be C-F1 "identical effects" cleanup).

tsc green, ruff clean, localdev boots healthy.
This commit is contained in:
npeter83 2026-07-11 17:43:18 +02:00
parent 3cbb420ece
commit 94417ada72
2 changed files with 19 additions and 4 deletions

View file

@ -184,9 +184,18 @@ export default function Feed({
setOverrides({});
setSavedOverrides({});
}, [filters]);
// ...but NOT on infinite-scroll appends: fetchNextPage also bumps dataUpdatedAt while page 1's
// rows are unchanged, so clearing overrides there would make a just-hidden card flash back.
// Only a real refetch (page count doesn't grow) is authoritative.
const pagesLenRef = useRef(0);
useEffect(() => {
setOverrides({});
setSavedOverrides({});
const len = query.data?.pages?.length ?? 0;
const appended = len > pagesLenRef.current;
pagesLenRef.current = len;
if (!appended) {
setOverrides({});
setSavedOverrides({});
}
}, [query.dataUpdatedAt]);
const countQuery = useQuery({