fix: resume tournament result polling after delayed codes
This commit is contained in:
1 parent
e50a683336
commit
2984bd1604
8 files changed
+207
-21
No files matched your search
@@ -1,5 +1,9 @@
|
||||
import mongoose from 'mongoose';
|
||||
import type { MatchDocument, MatchGameResult, TeamSide } from '../global/database/schema';
|
||||
import type {
|
||||
MatchDocument,
|
||||
MatchGameResult,
|
||||
TeamSide,
|
||||
} from '../global/database/schema';
|
||||
import type { RiotMatchDto } from '../riot/riot.types';
|
||||
|
||||
const RIOT_BLUE_TEAM_ID = 100;
|
||||
@@ -11,19 +15,46 @@ export interface MatchPuuidLookup {
|
||||
userIdByPuuid: Map<string, mongoose.Types.ObjectId>;
|
||||
}
|
||||
|
||||
export function collectCaptainUserIds(match: MatchDocument): mongoose.Types.ObjectId[] {
|
||||
export function collectCaptainUserIds(
|
||||
match: MatchDocument,
|
||||
): mongoose.Types.ObjectId[] {
|
||||
return match.teams
|
||||
.map((team) => team.captainUserId)
|
||||
.filter((userId): userId is mongoose.Types.ObjectId => Boolean(userId));
|
||||
}
|
||||
|
||||
export function collectMatchUserIds(match: MatchDocument): mongoose.Types.ObjectId[] {
|
||||
export function collectCaptainAndLimitedTeamMemberUserIds(
|
||||
match: MatchDocument,
|
||||
memberLimitPerTeam: number,
|
||||
): mongoose.Types.ObjectId[] {
|
||||
const ids = new Map<string, mongoose.Types.ObjectId>();
|
||||
for (const team of match.teams) {
|
||||
if (team.captainUserId) {
|
||||
ids.set(team.captainUserId.toString(), team.captainUserId);
|
||||
}
|
||||
let memberCount = 0;
|
||||
for (const member of team.members) {
|
||||
if (team.captainUserId?.toString() === member.userId.toString()) {
|
||||
continue;
|
||||
}
|
||||
if (memberCount >= memberLimitPerTeam) break;
|
||||
ids.set(member.userId.toString(), member.userId);
|
||||
memberCount += 1;
|
||||
}
|
||||
}
|
||||
return [...ids.values()];
|
||||
}
|
||||
|
||||
export function collectMatchUserIds(
|
||||
match: MatchDocument,
|
||||
): mongoose.Types.ObjectId[] {
|
||||
const ids = new Map<string, mongoose.Types.ObjectId>();
|
||||
for (const participant of match.participants) {
|
||||
ids.set(participant.userId.toString(), participant.userId);
|
||||
}
|
||||
for (const team of match.teams) {
|
||||
if (team.captainUserId) ids.set(team.captainUserId.toString(), team.captainUserId);
|
||||
if (team.captainUserId)
|
||||
ids.set(team.captainUserId.toString(), team.captainUserId);
|
||||
for (const member of team.members) {
|
||||
ids.set(member.userId.toString(), member.userId);
|
||||
}
|
||||
@@ -78,8 +109,10 @@ export function computeGameResult(params: {
|
||||
const reversedOverlap =
|
||||
countOverlap(team100Puuids, teamBPuuids) +
|
||||
countOverlap(team200Puuids, teamAPuuids);
|
||||
const blueTeamIndex = normalOverlap >= reversedOverlap ? teamAIndex : teamBIndex;
|
||||
const redTeamIndex = normalOverlap >= reversedOverlap ? teamBIndex : teamAIndex;
|
||||
const blueTeamIndex =
|
||||
normalOverlap >= reversedOverlap ? teamAIndex : teamBIndex;
|
||||
const redTeamIndex =
|
||||
normalOverlap >= reversedOverlap ? teamBIndex : teamAIndex;
|
||||
const teamIndexByRiotTeamId: Record<number, number> = {
|
||||
[RIOT_BLUE_TEAM_ID]: blueTeamIndex,
|
||||
[RIOT_RED_TEAM_ID]: redTeamIndex,
|
||||
|
||||
Reference in new issue
Block a user