一分钟搭建影视站,支持Docker等部署方式
refactor: 直播源批量启停一次 set 完成;修正测活缓存 TTL 注释
bestZweid8c22e6c1e0c
diff --git a/src/app/api/live/probe/route.ts b/src/app/api/live/probe/route.tsindex 4c908fa..683da7b 100644--- a/src/app/api/live/probe/route.ts+++ b/src/app/api/live/probe/route.ts@@ -509,7 +509,7 @@ function ndjsonResponse(urls: string[], reqSignal: AbortSignal): Response {return new NextResponse(stream, { headers: NDJSON_HEADERS });}-/** 结果短 TTL 缓存:成功 10min、失败 2min,避免多用户重复测活打爆上游 */+/** 结果短 TTL 缓存:成功 30min、失败 2min(TTL 见上方 CACHE_TTL_*_MS),避免多用户重复测活打爆上游 */const probeCache = new Map<string, { outcome: ProbeOutcome; expiresAt: number }>();function cacheGet(url: string): ProbeOutcome | undefined {diff --git a/src/components/live-source-manager.tsx b/src/components/live-source-manager.tsxindex bc299af..df2c42c 100644--- a/src/components/live-source-manager.tsx+++ b/src/components/live-source-manager.tsx@@ -81,12 +81,11 @@ export function LiveSourceManager() {const allEnabled = rows.length > 0 && rows.every((r) => store.liveSelectedUrls.includes(r.url));const toggleAll = () => {- // 单次事件内的多次 set 会被 React 批处理合并;用 getState 保证基于最新状态切换- if (allEnabled) {- rows.filter((r) => store.liveSelectedUrls.includes(r.url)).forEach((r) => useAppStore.getState().toggleLiveSelected(r.url));- return;- }- rows.filter((r) => !store.liveSelectedUrls.includes(r.url)).forEach((r) => useAppStore.getState().toggleLiveSelected(r.url));+ // 只翻转状态与目标不一致的源,一次批量 set 完成(逐条 toggle 会触发 O(n) 次持久化)+ const targets = rows+ .filter((r) => store.liveSelectedUrls.includes(r.url) === allEnabled)+ .map((r) => r.url);+ if (targets.length > 0) useAppStore.getState().toggleLiveSelectedMany(targets);};const removeWithUndo = (row: LiveRow) => {diff --git a/src/lib/store.ts b/src/lib/store.tsindex 0de397a..188bedb 100644--- a/src/lib/store.ts+++ b/src/lib/store.ts@@ -225,6 +225,8 @@ interface AppState extends AppSettings {updateLiveSubscription: (url: string, patch: { name?: string; epg?: string }) => void;markLiveSynced: (url: string, name?: string, epg?: string) => void;toggleLiveSelected: (url: string) => void;+ /** 批量启停直播源:一次 set 完成,避免逐条 toggle 的 O(n) 次持久化 */+ toggleLiveSelectedMany: (urls: string[]) => void;toggleLiveFavorite: (channelUrl: string) => void;addLiveRecent: (entry: Omit<LiveRecentEntry, 'timestamp'>) => void;/** 删除单条最近观看(按流 URL) */@@ -563,6 +565,16 @@ export const useAppStore = create<AppState>()(});},+ // 批量启停:一次 set 替代 N 次逐条 toggle(每条都会触发一次完整 persist 序列化)+ toggleLiveSelectedMany: (urls) => {+ const cur = get().liveSelectedUrls;+ let next = cur;+ for (const url of urls) {+ next = next.includes(url) ? next.filter((u) => u !== url) : [...next, url];+ }+ set({ liveSelectedUrls: next });+ },+markLiveSynced: (url, name, epg) => {set({liveSubscriptions: get().liveSubscriptions.map((s) =>