fix: guard competition stats rebuild revisions

This commit is contained in:
dahyeon committed 2026-07-12 19:40:29 +00:00
1 parent ee4c3eeb27
commit 4d6fa2625e
2 files changed
+60 -3

No files matched your search

@@ -26,7 +26,7 @@ export class MatchStatsService {
public async buildAndUpsert(
matchId: mongoose.Types.ObjectId,
options: { includeTimeline?: boolean } = {},
options: { includeTimeline?: boolean; sourceRevision?: number } = {},
): Promise<void> {
const MatchModel = await this.connectionService.getModel('match');
const CompetitionModel =
@@ -37,6 +37,12 @@ export class MatchStatsService {
const competition = await CompetitionModel.findOne({ matchId })
.lean()
.exec();
if (
options.sourceRevision !== undefined &&
(!competition || competition.revision < options.sourceRevision)
) {
return;
}
const competitionSource = competition
? competitionStatsSource(match, competition)
: undefined;
@@ -148,7 +154,10 @@ export class MatchStatsService {
const matches = await MatchModel.find({
communityId,
status: { $in: ['finished', 'in-progress'] },
'result.games.0': { $exists: true },
$or: [
{ competitionId: { $exists: true } },
{ 'result.games.0': { $exists: true } },
],
})
.sort({ scheduledAt: -1 })
.select({ _id: 1 })