Collect match timelines during analysis

This commit is contained in:
dahyeon committed 2026-07-02 22:38:24 -07:00
1 parent 304f157b91
commit 43662a86d8
2 files changed
+164 -10

No files matched your search

@@ -42,6 +42,10 @@ function asRecord(value: unknown): Record<string, unknown> {
return {};
}
function isRecordValue(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
function asNumber(value: unknown, fallback = 0): number {
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
}
@@ -225,6 +229,11 @@ export class AnalysisPipelineService {
if (existingMatch) {
if (this.isEligibleMatch(existingMatch.raw, data.queueId)) {
await this.fetchAndStoreMissingTimeline(
matchId,
existingMatch.timeline,
data.regionalRoute,
);
matchRecords.push({ matchId, raw: existingMatch.raw });
}
} else {
@@ -234,6 +243,11 @@ export class AnalysisPipelineService {
);
await this.storeRiotMatch(matchId, rawMatch);
if (this.isEligibleMatch(rawMatch, data.queueId)) {
await this.fetchAndStoreMissingTimeline(
matchId,
undefined,
data.regionalRoute,
);
matchRecords.push({ matchId, raw: rawMatch });
}
}
@@ -281,6 +295,47 @@ export class AnalysisPipelineService {
.exec();
}
private async fetchAndStoreMissingTimeline(
matchId: string,
existingTimeline: unknown,
regionalRoute: UserAnalysisJobData['regionalRoute'],
): Promise<void> {
if (isRecordValue(existingTimeline)) {
return;
}
try {
const timeline = await this.riotApiClient.getMatchTimeline(
matchId,
regionalRoute,
);
await this.storeRiotMatchTimeline(matchId, timeline);
} catch (error) {
this.logger.warn(
`Skipping timeline fetch for matchId="${this.safeLogText(matchId)}": ${this.safeLogText(errorMessage(error))}`,
);
}
}
private async storeRiotMatchTimeline(
matchId: string,
timeline: Record<string, unknown>,
): Promise<void> {
const riotMatchModel = await this.connectionService.getModel('riotMatch');
await riotMatchModel
.updateOne(
{ matchId },
{
$set: {
timeline,
timelineFetchedAt: new Date(),
},
},
)
.exec();
}
private async extractAndStoreFeatures(
matchRecords: MatchRecord[],
puuid: string,