From 597b1186ab805b270c410bb244e4eac9cbfaabcb Mon Sep 17 00:00:00 2001 From: ayrisdev Date: Wed, 2 Sep 2026 23:20:58 +0300 Subject: [PATCH] =?UTF-8?q?perf:=20zaten=20kay=C4=B1tta=20olan=20kanallar?= =?UTF-8?q?=C4=B1=20tekrar=20poll=20etme=20+=20kontroller=20aras=C4=B1na?= =?UTF-8?q?=20gecikme=20ekle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pollOnce her döngüde AKTİF kanalların hepsini (zaten kayıtta olanlar dahil) yt-dlp'nin bot-check riskli /live sorgusuna sokuyordu — gereksiz. Birden fazla kanal aynı anda canlıyken bu, aynı paylaşılan cookie+proxy üzerinden gereksiz istek hacmi katlıyordu (muhtemelen 4-5 kanal eklenince birkaç kanalın aynı anda tespit hatası vermeye başlamasının sebeplerinden biri). Artık zaten açık bir StreamSession'ı olan kanal tamamen atlanıyor, kalan kanallar arasına da 2sn gecikme eklendi (art arda patlama yerine seyrek). Co-Authored-By: Claude Sonnet 5 --- apps/api-daemon/src/youtubePolling.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/api-daemon/src/youtubePolling.ts b/apps/api-daemon/src/youtubePolling.ts index 4c0434f..087ec7d 100644 --- a/apps/api-daemon/src/youtubePolling.ts +++ b/apps/api-daemon/src/youtubePolling.ts @@ -155,12 +155,31 @@ export async function checkChannel(channel: { export async function pollOnce(): Promise { const channels = await prisma.channel.findMany({ where: { isActive: true } }); + const openSessions = await prisma.streamSession.findMany({ + where: { endedAt: null, channelId: { in: channels.map((c) => c.id) } }, + select: { channelId: true }, + }); + const recordingChannelIds = new Set(openSessions.map((s) => s.channelId)); + for (const channel of channels) { + // Already capturing this channel — we already know it's live, so skip + // the bot-check-prone /live lookup entirely. With several channels + // sharing one cookie session + one proxy IP, re-checking channels that + // don't need it multiplies request volume through that single shared + // identity for no reason — a likely contributor to multiple channels + // failing detection at once once a few are live simultaneously. + if (recordingChannelIds.has(channel.id)) continue; + try { await checkChannel(channel); } catch (err) { console.error(`[youtube-polling] error polling channel ${channel.name}:`, err); } + + // Stagger checks instead of firing them back-to-back — a tight burst of + // near-simultaneous requests through the same cookie/IP looks more + // automated than the same requests spread out. + await new Promise((resolve) => setTimeout(resolve, 2000)); } }