fix: guard competition stats rebuild revisions
This commit is contained in:
1 parent
ee4c3eeb27
commit
4d6fa2625e
2 files changed
+60
-3
No files matched your search
@@ -206,7 +206,7 @@ describe('MatchStatsService', () => {
|
||||
{ getMatchTimeline: jest.fn() } as never,
|
||||
);
|
||||
|
||||
await service.buildAndUpsert(matchId);
|
||||
await service.buildAndUpsert(matchId, { sourceRevision: 12 });
|
||||
|
||||
expect(riotFind).toHaveBeenCalledWith({
|
||||
matchId: { $in: ['KR_COMPETITION'] },
|
||||
@@ -236,6 +236,54 @@ describe('MatchStatsService', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('does not rebuild before the requested Competition revision is visible', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const riotFind = jest.fn();
|
||||
const connectionService = {
|
||||
getModel: jest.fn().mockImplementation(async (name: string) => {
|
||||
if (name === 'match') {
|
||||
return {
|
||||
findById: () =>
|
||||
queryResult(
|
||||
{
|
||||
_id: matchId,
|
||||
status: 'in-progress',
|
||||
},
|
||||
false,
|
||||
),
|
||||
};
|
||||
}
|
||||
if (name === 'competition') {
|
||||
return {
|
||||
findOne: () => queryResult({ revision: 11 }),
|
||||
};
|
||||
}
|
||||
if (name === 'riotMatch') return { find: riotFind };
|
||||
throw new Error(`Unexpected model: ${name}`);
|
||||
}),
|
||||
} as unknown as ConnectionService;
|
||||
const repository = {
|
||||
upsert: jest.fn(),
|
||||
deleteByMatch: jest.fn(),
|
||||
} as unknown as jest.Mocked<MatchStatsRepository>;
|
||||
const builder = {
|
||||
buildFragment: jest.fn(),
|
||||
} as unknown as jest.Mocked<MatchStatsFragmentBuilder>;
|
||||
const service = new MatchStatsService(
|
||||
connectionService,
|
||||
repository,
|
||||
builder,
|
||||
{ getMatchTimeline: jest.fn() } as never,
|
||||
);
|
||||
|
||||
await service.buildAndUpsert(matchId, { sourceRevision: 12 });
|
||||
|
||||
expect(riotFind).not.toHaveBeenCalled();
|
||||
expect(builder.buildFragment).not.toHaveBeenCalled();
|
||||
expect(repository.upsert).not.toHaveBeenCalled();
|
||||
expect(repository.deleteByMatch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
function participant(
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in new issue
Block a user