fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
@@ -48,7 +48,14 @@ export class MatchStatsService {
|
||||
: undefined;
|
||||
const sourceMatch = competitionSource?.match ?? match;
|
||||
if (!this.isEligible(sourceMatch)) {
|
||||
await this.repository.deleteByMatch(matchId);
|
||||
if (competitionSource) {
|
||||
await this.repository.deleteByMatch(matchId, {
|
||||
sourceCompetitionId: competitionSource.sourceCompetitionId,
|
||||
sourceRevision: competitionSource.sourceRevision,
|
||||
});
|
||||
} else {
|
||||
await this.repository.deleteByMatch(matchId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -135,6 +142,11 @@ export class MatchStatsService {
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
|
||||
// Source reads and the read-model write are intentionally separated by
|
||||
// Riot/timeline work. Revalidate after the write so a concurrent aggregate
|
||||
// deletion cannot resurrect MatchStats after the delete transaction.
|
||||
await this.removeFragmentIfSourceChanged(matchId, competitionSource);
|
||||
}
|
||||
|
||||
public async removeByMatch(matchId: mongoose.Types.ObjectId): Promise<void> {
|
||||
@@ -196,6 +208,49 @@ export class MatchStatsService {
|
||||
? (region as RiotRegionalRoute)
|
||||
: 'asia';
|
||||
}
|
||||
|
||||
private async removeFragmentIfSourceChanged(
|
||||
matchId: mongoose.Types.ObjectId,
|
||||
source:
|
||||
| {
|
||||
sourceCompetitionId: mongoose.Types.ObjectId;
|
||||
sourceRevision: number;
|
||||
}
|
||||
| undefined,
|
||||
): Promise<void> {
|
||||
const [MatchModel, CompetitionModel] = await Promise.all([
|
||||
this.connectionService.getModel('match'),
|
||||
this.connectionService.getModel('competition'),
|
||||
]);
|
||||
const [currentMatch, currentCompetition] = await Promise.all([
|
||||
MatchModel.findById(matchId).exec(),
|
||||
CompetitionModel.findOne({
|
||||
matchId,
|
||||
...(source
|
||||
? {
|
||||
_id: source.sourceCompetitionId,
|
||||
revision: source.sourceRevision,
|
||||
}
|
||||
: {}),
|
||||
})
|
||||
.lean()
|
||||
.exec(),
|
||||
]);
|
||||
|
||||
if (source) {
|
||||
if (!currentMatch || !currentCompetition) {
|
||||
await this.repository.deleteByMatch(matchId, {
|
||||
sourceCompetitionId: source.sourceCompetitionId,
|
||||
sourceRevision: source.sourceRevision,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentMatch || currentCompetition) {
|
||||
await this.repository.deleteLegacyByMatch(matchId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isRiotMatchTimelineDto(value: unknown): value is RiotMatchTimelineDto {
|
||||
|
||||
Reference in new issue
Block a user