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
@@ -80,6 +80,7 @@ type ParsedMatchSideEffectMutation =
|
||||
| { type: typeof UNDO_COMPLETED_MATCH_SIDE_EFFECT_TYPE };
|
||||
|
||||
interface CleanupSideEffectMatchDocument {
|
||||
competitionId?: unknown;
|
||||
gameSchedule?: unknown[];
|
||||
participants: Array<{ excluded?: boolean }>;
|
||||
result?: unknown;
|
||||
@@ -420,13 +421,14 @@ export class AuctionDurabilityScheduler
|
||||
},
|
||||
);
|
||||
if (!processingDelta) return;
|
||||
let expectedMatchSideEffectRevision =
|
||||
const expectedMatchSideEffectRevision =
|
||||
processingDelta.matchSideEffectRevision;
|
||||
|
||||
try {
|
||||
const match = (await execMaybe(
|
||||
MatchModel.findById(payload.matchId) as never,
|
||||
)) as {
|
||||
competitionId?: unknown;
|
||||
participants: Array<{
|
||||
preferredPositions?: Array<{ position?: Position }>;
|
||||
userId: { toString(): string };
|
||||
@@ -438,39 +440,50 @@ export class AuctionDurabilityScheduler
|
||||
} | null;
|
||||
if (!match)
|
||||
throw new Error(`Match not found: ${String(payload.matchId)}`);
|
||||
const matchTeams = buildMatchTeamsFromProjection(
|
||||
payload.afterAuctionMongoProjection,
|
||||
match,
|
||||
);
|
||||
// [AUCTION-DEBUG] 제거 대상. 최종 팀에 같은 유저가 2번 들어갔는지 무조건 검사
|
||||
// (출처가 markSold든 undo 복원이든 projection이든 여기서 결정적으로 잡힌다).
|
||||
const allMemberUserIds = matchTeams.flatMap((team) =>
|
||||
team.members.map((member) => member.userId.toString()),
|
||||
);
|
||||
const distinctMemberCount = new Set(allMemberUserIds).size;
|
||||
recordNewRelicCustomEvent('AuctionServerTeamBuild', {
|
||||
matchId: typeof payload.matchId === 'string' ? payload.matchId : '',
|
||||
auctionStateTransitionId: payload.auctionStateTransitionId,
|
||||
teamCount: matchTeams.length,
|
||||
totalMemberCount: allMemberUserIds.length,
|
||||
distinctMemberCount,
|
||||
hasDuplicateMember: allMemberUserIds.length !== distinctMemberCount,
|
||||
duplicateUserId:
|
||||
allMemberUserIds.find(
|
||||
(id, idx) => allMemberUserIds.indexOf(id) !== idx,
|
||||
) ?? null,
|
||||
});
|
||||
if (matchTeams.length === 0) {
|
||||
throw new Error(
|
||||
`Auction complete side effect produced no match teams for match ${String(payload.matchId)}.`,
|
||||
if (match.competitionId) {
|
||||
await this.tournamentResultService.scheduleInitialPoll(match as never);
|
||||
} else {
|
||||
const matchTeams = buildMatchTeamsFromProjection(
|
||||
payload.afterAuctionMongoProjection,
|
||||
match,
|
||||
);
|
||||
// [AUCTION-DEBUG] 제거 대상. 최종 팀에 같은 유저가 2번 들어갔는지 무조건 검사
|
||||
// (출처가 markSold든 undo 복원이든 projection이든 여기서 결정적으로 잡힌다).
|
||||
const allMemberUserIds = matchTeams.flatMap((team) =>
|
||||
team.members.map((member) => member.userId.toString()),
|
||||
);
|
||||
const distinctMemberCount = new Set(allMemberUserIds).size;
|
||||
recordNewRelicCustomEvent('AuctionServerTeamBuild', {
|
||||
matchId: typeof payload.matchId === 'string' ? payload.matchId : '',
|
||||
auctionStateTransitionId: payload.auctionStateTransitionId,
|
||||
teamCount: matchTeams.length,
|
||||
totalMemberCount: allMemberUserIds.length,
|
||||
distinctMemberCount,
|
||||
hasDuplicateMember: allMemberUserIds.length !== distinctMemberCount,
|
||||
duplicateUserId:
|
||||
allMemberUserIds.find(
|
||||
(id, idx) => allMemberUserIds.indexOf(id) !== idx,
|
||||
) ?? null,
|
||||
});
|
||||
if (matchTeams.length === 0) {
|
||||
throw new Error(
|
||||
`Auction complete side effect produced no match teams for match ${String(payload.matchId)}.`,
|
||||
);
|
||||
}
|
||||
const finalizedAt = match.teamBuiltAt ?? new Date();
|
||||
match.teams = matchTeams;
|
||||
match.status = 'team-built';
|
||||
match.teamBuiltAt = undefined;
|
||||
await match.save();
|
||||
const preparedMatch =
|
||||
(await this.tournamentCodeService.reserveForMatch(match as never)) ??
|
||||
match;
|
||||
preparedMatch.teamBuiltAt = finalizedAt;
|
||||
await preparedMatch.save();
|
||||
await this.tournamentResultService.scheduleInitialPoll(
|
||||
preparedMatch as never,
|
||||
);
|
||||
}
|
||||
match.teams = matchTeams;
|
||||
match.status = 'team-built';
|
||||
match.teamBuiltAt = match.teamBuiltAt ?? new Date();
|
||||
await match.save();
|
||||
await this.tournamentCodeService.reserveForMatch(match as never);
|
||||
await this.tournamentResultService.scheduleInitialPoll(match as never);
|
||||
|
||||
const completedAtTimestampMS =
|
||||
await this.auctionRedisService.getCurrentRedisTimestampMS();
|
||||
@@ -543,7 +556,9 @@ export class AuctionDurabilityScheduler
|
||||
await this.isAppendHistoryInvalidatedByLaterDestructiveMutation(params);
|
||||
if (invalidated) return;
|
||||
|
||||
const historyOperation = buildAuctionHistoryUpsert(params.payload).updateOne;
|
||||
const historyOperation = buildAuctionHistoryUpsert(
|
||||
params.payload,
|
||||
).updateOne;
|
||||
await execMaybe(
|
||||
params.AuctionHistoryModel.updateOne(
|
||||
historyOperation.filter as never,
|
||||
@@ -700,7 +715,7 @@ export class AuctionDurabilityScheduler
|
||||
},
|
||||
);
|
||||
if (!processingDelta) return;
|
||||
let expectedMatchSideEffectRevision =
|
||||
const expectedMatchSideEffectRevision =
|
||||
processingDelta.matchSideEffectRevision;
|
||||
|
||||
try {
|
||||
@@ -710,6 +725,11 @@ export class AuctionDurabilityScheduler
|
||||
if (!match) {
|
||||
throw new Error(`Match not found: ${String(params.payload.matchId)}`);
|
||||
}
|
||||
if (match.competitionId) {
|
||||
throw new Error(
|
||||
'Cannot reset or undo Match teams after the immutable Competition has been created.',
|
||||
);
|
||||
}
|
||||
await params.updateMatch(match);
|
||||
|
||||
const completedAtTimestampMS =
|
||||
|
||||
Reference in new issue
Block a user