refactor(EventSubscribeService): switch to sequential execution and add debug logs
- Replace Promise.all concurrency with sequential for...of loop when fetching event info and match details - Add console.debug logs to track event processing status and URL retrieval - Improves visibility into the event fetching flow for easier debugging - Ensures events are processed one by one before being categorized
This commit is contained in:
parent
16b2899946
commit
77530d4c65
@ -1,5 +1,5 @@
|
|||||||
import { prisma } from "../prisma/db";
|
import { prisma } from "../prisma/db";
|
||||||
import { xcxApi } from "../utils/server";
|
import type { EventDetail } from "../types";
|
||||||
import { KaiqiuService } from "./KaiqiuService";
|
import { KaiqiuService } from "./KaiqiuService";
|
||||||
|
|
||||||
export class EventSubscribeService {
|
export class EventSubscribeService {
|
||||||
@ -48,7 +48,15 @@ export class EventSubscribeService {
|
|||||||
select: { event_id: true },
|
select: { event_id: true },
|
||||||
distinct: 'event_id',
|
distinct: 'event_id',
|
||||||
}).then(v => v.map(e => e.event_id));
|
}).then(v => v.map(e => e.event_id));
|
||||||
const events = await Promise.all(eids.map(eid => KaiqiuService.getEventInfo(eid)));
|
const events = [];
|
||||||
|
for (const eid of eids) {
|
||||||
|
const info = await KaiqiuService.getEventInfo(eid)
|
||||||
|
console.debug(
|
||||||
|
'Getting event info for %s - %s, should check: %s',
|
||||||
|
info.title, info.eventId, !info.isFinished && !info.isProcessing,
|
||||||
|
);
|
||||||
|
events.push(info);
|
||||||
|
}
|
||||||
const expiredEvents = events.filter(e => e.isFinished || e.isProcessing);
|
const expiredEvents = events.filter(e => e.isFinished || e.isProcessing);
|
||||||
const beforeEvents = events.filter(e => !e.isFinished && !e.isProcessing);
|
const beforeEvents = events.filter(e => !e.isFinished && !e.isProcessing);
|
||||||
await prisma.eventSubs.deleteMany({
|
await prisma.eventSubs.deleteMany({
|
||||||
@ -56,10 +64,12 @@ export class EventSubscribeService {
|
|||||||
event_id: { in: expiredEvents.map(e => e.eventId) }
|
event_id: { in: expiredEvents.map(e => e.eventId) }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const [requests] = await Promise.all([
|
const details: EventDetail[] = [];
|
||||||
beforeEvents.map(e => KaiqiuService.getMatchDetail(e.eventId, true)),
|
for (const e of beforeEvents) {
|
||||||
]);
|
const result = await KaiqiuService.getMatchDetail(e.eventId, true)
|
||||||
const details = await Promise.all(requests);
|
console.debug('Get match detail: %s - %s, url: %s', e.title, e.eventId, e.url)
|
||||||
|
details.push(result);
|
||||||
|
}
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user