perf: zaten kayıtta olan kanalları tekrar poll etme + kontroller arasına gecikme ekle
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 <noreply@anthropic.com>
This commit is contained in:
@@ -155,12 +155,31 @@ export async function checkChannel(channel: {
|
|||||||
export async function pollOnce(): Promise<void> {
|
export async function pollOnce(): Promise<void> {
|
||||||
const channels = await prisma.channel.findMany({ where: { isActive: true } });
|
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) {
|
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 {
|
try {
|
||||||
await checkChannel(channel);
|
await checkChannel(channel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[youtube-polling] error polling channel ${channel.name}:`, 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user