From d216904b76ab3f1698e0df335ecc7c4fc79c3527 Mon Sep 17 00:00:00 2001 From: shinya Date: Sun, 24 Aug 2025 17:32:47 +0800 Subject: [PATCH] feat: concurrent refresh in cron --- src/app/api/cron/route.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/app/api/cron/route.ts b/src/app/api/cron/route.ts index 9d1db89..374b2ee 100644 --- a/src/app/api/cron/route.ts +++ b/src/app/api/cron/route.ts @@ -365,17 +365,24 @@ async function cronJob() { async function refreshAllLiveChannels() { const config = await getConfig(); - for (const liveInfo of config.LiveConfig || []) { - if (liveInfo.disabled) { - continue; - } - try { - const nums = await refreshLiveChannels(liveInfo); - liveInfo.channelNumber = nums; - } catch (error) { - console.error('刷新直播源失败:', error); - } - } + + // 并发刷新所有启用的直播源 + const refreshPromises = (config.LiveConfig || []) + .filter(liveInfo => !liveInfo.disabled) + .map(async (liveInfo) => { + try { + const nums = await refreshLiveChannels(liveInfo); + liveInfo.channelNumber = nums; + } catch (error) { + console.error(`刷新直播源失败 [${liveInfo.name || liveInfo.key}]:`, error); + liveInfo.channelNumber = 0; + } + }); + + // 等待所有刷新任务完成 + await Promise.all(refreshPromises); + + // 保存配置 await db.saveAdminConfig(config); }