Auto-reindex channel on page visit if stale

GET /channels/{id} now fires a background _index_channel_task if the
channel hasn't been crawled in the last hour. The frontend refetches
channel + videos 8s after page load to pick up the updated data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 22:02:59 +02:00
parent 871f668525
commit d740fd5224
2 changed files with 24 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useMemo } from "react";
import { useState, useMemo, useEffect, useRef } from "react";
import { useParams } from "react-router-dom";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { getChannel, getChannelVideos, followChannel, unfollowChannel, indexChannel, downloadChannel } from "../api";
@@ -41,6 +41,18 @@ export default function ChannelPage() {
queryFn: () => getChannelVideos(id).then((r) => r.data),
});
// Refetch after the background re-index has had time to run
const refetchedRef = useRef(false);
useEffect(() => {
if (!id || refetchedRef.current) return;
refetchedRef.current = true;
const t = setTimeout(() => {
qc.invalidateQueries({ queryKey: ["channel", id] });
qc.invalidateQueries({ queryKey: ["channel-videos", id] });
}, 8000);
return () => clearTimeout(t);
}, [id, qc]);
const followMut = useMutation({
mutationFn: () =>
channel?.status === "followed" ? unfollowChannel(id) : followChannel(id),