perf(enrich): параллельная обработка очереди (3 трека) — быстрее покрывать живой набор

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
nk
2026-06-03 14:49:25 +03:00
parent bb74d631c1
commit 554c1730a3

View File

@@ -17,7 +17,8 @@ export class EnrichmentService {
// Очередь обогащения с троттлингом (под лимиты Discogs/iTunes) // Очередь обогащения с троттлингом (под лимиты Discogs/iTunes)
private readonly queue: string[] = []; private readonly queue: string[] = [];
private running = false; private running = false;
private readonly throttleMs = 1500; private readonly throttleMs = 1000;
private readonly concurrency = 3;
constructor( constructor(
private readonly prisma: PrismaService, private readonly prisma: PrismaService,
@@ -94,9 +95,8 @@ export class EnrichmentService {
this.running = true; this.running = true;
try { try {
while (this.queue.length > 0) { while (this.queue.length > 0) {
const id = this.queue.shift(); const batch = this.queue.splice(0, this.concurrency);
if (!id) continue; await Promise.all(batch.map((id) => this.enrichOne(id)));
await this.enrichOne(id);
await this.sleep(this.throttleMs); await this.sleep(this.throttleMs);
} }
} finally { } finally {