.
This commit is contained in:
1 parent
b38cc03a71
commit
1fd37f992b
6 files changed
+168
-1
No files matched your search
@@ -123,6 +123,16 @@ export class LegacyImportController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('legacy-matches/rebuild')
|
||||||
|
public rebuildLegacyMatches(
|
||||||
|
@CurrentUser() currentUser: UserDocument,
|
||||||
|
@Param('communityId', ParseObjectIdPipe)
|
||||||
|
communityId: mongoose.Types.ObjectId,
|
||||||
|
) {
|
||||||
|
this.assertSameCommunity(currentUser, communityId);
|
||||||
|
return this.legacyImportService.rebuildLegacyMatches({ communityId });
|
||||||
|
}
|
||||||
|
|
||||||
private assertSameCommunity(
|
private assertSameCommunity(
|
||||||
user: UserDocument,
|
user: UserDocument,
|
||||||
communityId: mongoose.Types.ObjectId,
|
communityId: mongoose.Types.ObjectId,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import {
|
|||||||
type LegacyImportMemberJob,
|
type LegacyImportMemberJob,
|
||||||
type LegacyImportMemberWindowView,
|
type LegacyImportMemberWindowView,
|
||||||
type LegacyMatchListResponse,
|
type LegacyMatchListResponse,
|
||||||
|
type RebuildLegacyMatchesResponse,
|
||||||
type StartLegacyImportRequest,
|
type StartLegacyImportRequest,
|
||||||
type StartLegacyImportResponse,
|
type StartLegacyImportResponse,
|
||||||
} from './legacy-import.types';
|
} from './legacy-import.types';
|
||||||
@@ -335,6 +336,102 @@ export class LegacyImportService {
|
|||||||
return { deleted: result.deletedCount ?? 0 };
|
return { deleted: result.deletedCount ?? 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async rebuildLegacyMatches(params: {
|
||||||
|
communityId: mongoose.Types.ObjectId;
|
||||||
|
}): Promise<RebuildLegacyMatchesResponse> {
|
||||||
|
const MatchModel = await this.connectionService.getModel('match');
|
||||||
|
const matches = await MatchModel.find({
|
||||||
|
communityId: params.communityId,
|
||||||
|
legacyImported: true,
|
||||||
|
}).exec();
|
||||||
|
const riotMatchIds = matches
|
||||||
|
.map(
|
||||||
|
(match) =>
|
||||||
|
match.result?.games[0]?.riotMatchId ?? match.result?.riotMatchIds?.[0],
|
||||||
|
)
|
||||||
|
.filter((matchId): matchId is string => Boolean(matchId));
|
||||||
|
|
||||||
|
const RiotMatchModel = await this.connectionService.getModel('riotMatch');
|
||||||
|
const rawDocs = await RiotMatchModel.find({ matchId: { $in: riotMatchIds } })
|
||||||
|
.lean()
|
||||||
|
.exec();
|
||||||
|
const rawById = new Map<string, RiotMatchDto>();
|
||||||
|
for (const doc of rawDocs) {
|
||||||
|
if (isRiotMatchDto(doc.raw)) rawById.set(doc.matchId, doc.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
const userByPuuid = await this.buildUserByPuuidMap(params.communityId);
|
||||||
|
const result: RebuildLegacyMatchesResponse = {
|
||||||
|
scanned: matches.length,
|
||||||
|
rebuilt: 0,
|
||||||
|
normalizedTitles: 0,
|
||||||
|
skippedMissingRaw: 0,
|
||||||
|
skippedNoKnownParticipants: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const match of matches) {
|
||||||
|
const riotMatchId =
|
||||||
|
match.result?.games[0]?.riotMatchId ?? match.result?.riotMatchIds?.[0];
|
||||||
|
const raw = riotMatchId ? rawById.get(riotMatchId) : undefined;
|
||||||
|
const title = this.normalizeLegacyTitle(
|
||||||
|
match.title,
|
||||||
|
raw?.info.gameCreation ?? match.scheduledAt.getTime(),
|
||||||
|
);
|
||||||
|
const update: Partial<Match> = {};
|
||||||
|
if (title !== match.title) {
|
||||||
|
update.title = title;
|
||||||
|
result.normalizedTitles += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!raw || !riotMatchId) {
|
||||||
|
result.skippedMissingRaw += 1;
|
||||||
|
if (Object.keys(update).length > 0) {
|
||||||
|
await MatchModel.updateOne({ _id: match._id }, { $set: update }).exec();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const team100IsBlue = resolveTeam100IsBlue(raw, userByPuuid);
|
||||||
|
const participants = buildParticipantsSnapshot(raw, userByPuuid);
|
||||||
|
const gameResult = buildGameResult(raw, userByPuuid, team100IsBlue, 1);
|
||||||
|
if (!gameResult || participants.length === 0) {
|
||||||
|
result.skippedNoKnownParticipants += 1;
|
||||||
|
if (Object.keys(update).length > 0) {
|
||||||
|
await MatchModel.updateOne({ _id: match._id }, { $set: update }).exec();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const winnerSide = gameResult.winnerSide;
|
||||||
|
update.mapId = raw.info.mapId ?? match.mapId;
|
||||||
|
update.participants = participants;
|
||||||
|
update.teams = buildTeams(raw, userByPuuid, team100IsBlue);
|
||||||
|
update.result = {
|
||||||
|
winnerSide,
|
||||||
|
blueScore: winnerSide === 'blue' ? 1 : 0,
|
||||||
|
redScore: winnerSide === 'red' ? 1 : 0,
|
||||||
|
riotMatchIds: [riotMatchId],
|
||||||
|
games: [gameResult],
|
||||||
|
};
|
||||||
|
|
||||||
|
await MatchModel.updateOne(
|
||||||
|
{
|
||||||
|
_id: match._id,
|
||||||
|
communityId: params.communityId,
|
||||||
|
legacyImported: true,
|
||||||
|
},
|
||||||
|
{ $set: update },
|
||||||
|
).exec();
|
||||||
|
result.rebuilt += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.rebuilt > 0 || result.normalizedTitles > 0) {
|
||||||
|
await this.communityStatsService.invalidateCommunity(params.communityId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private async collectMatchIds(job: LegacyImportMemberJob): Promise<Set<string>> {
|
private async collectMatchIds(job: LegacyImportMemberJob): Promise<Set<string>> {
|
||||||
const matchIds = new Set<string>();
|
const matchIds = new Set<string>();
|
||||||
let start = 0;
|
let start = 0;
|
||||||
@@ -386,7 +483,7 @@ export class LegacyImportService {
|
|||||||
const winnerSide = gameResult.winnerSide;
|
const winnerSide = gameResult.winnerSide;
|
||||||
const matchPayload: Partial<Match> = {
|
const matchPayload: Partial<Match> = {
|
||||||
communityId: new mongoose.Types.ObjectId(job.communityId),
|
communityId: new mongoose.Types.ObjectId(job.communityId),
|
||||||
title: `[Legacy] ${this.formatLegacyDate(detail.info.gameCreation)}`,
|
title: this.formatLegacyDate(detail.info.gameCreation),
|
||||||
description: 'Legacy import (자동 생성)',
|
description: 'Legacy import (자동 생성)',
|
||||||
mapId: detail.info.mapId ?? 11,
|
mapId: detail.info.mapId ?? 11,
|
||||||
status: 'finished',
|
status: 'finished',
|
||||||
@@ -647,6 +744,11 @@ export class LegacyImportService {
|
|||||||
return new Date(Math.min(...values.filter(Boolean).map((date) => date!.getTime())));
|
return new Date(Math.min(...values.filter(Boolean).map((date) => date!.getTime())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private normalizeLegacyTitle(title: string, gameCreation: number): string {
|
||||||
|
const stripped = title.replace(/^\[(?:legacy|lagacy)\]\s*/i, '').trim();
|
||||||
|
return stripped || this.formatLegacyDate(gameCreation);
|
||||||
|
}
|
||||||
|
|
||||||
private formatLegacyDate(gameCreation: number): string {
|
private formatLegacyDate(gameCreation: number): string {
|
||||||
return new Intl.DateTimeFormat('ko-KR', {
|
return new Intl.DateTimeFormat('ko-KR', {
|
||||||
timeZone: 'Asia/Seoul',
|
timeZone: 'Asia/Seoul',
|
||||||
|
|||||||
@@ -65,3 +65,11 @@ export interface LegacyMatchListResponse {
|
|||||||
export interface BulkDeleteLegacyMatchesRequest {
|
export interface BulkDeleteLegacyMatchesRequest {
|
||||||
matchIds?: string[];
|
matchIds?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RebuildLegacyMatchesResponse {
|
||||||
|
scanned: number;
|
||||||
|
rebuilt: number;
|
||||||
|
normalizedTitles: number;
|
||||||
|
skippedMissingRaw: number;
|
||||||
|
skippedNoKnownParticipants: number;
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ import type {
|
|||||||
MeResponse,
|
MeResponse,
|
||||||
RiotQueueGroup,
|
RiotQueueGroup,
|
||||||
RiotRankFilter,
|
RiotRankFilter,
|
||||||
|
RebuildLegacyMatchesResponse,
|
||||||
TournamentCodeBulkUploadResponse,
|
TournamentCodeBulkUploadResponse,
|
||||||
TournamentCodeListResponse,
|
TournamentCodeListResponse,
|
||||||
TournamentCodeState,
|
TournamentCodeState,
|
||||||
@@ -619,6 +620,16 @@ export function useBulkDeleteLegacyMatches(communityId = DEFAULT_COMMUNITY_ID) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useRebuildLegacyMatches(communityId = DEFAULT_COMMUNITY_ID) {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: () =>
|
||||||
|
apiFetch<RebuildLegacyMatchesResponse>(
|
||||||
|
`/communities/${communityId}/legacy-matches/rebuild`,
|
||||||
|
{ method: 'POST' },
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useMe() {
|
export function useMe() {
|
||||||
const authUserId = useAuthUserId();
|
const authUserId = useAuthUserId();
|
||||||
const { accounts, inProgress, instance } = useMsal();
|
const { accounts, inProgress, instance } = useMsal();
|
||||||
|
|||||||
@@ -704,6 +704,14 @@ export interface LegacyMatchListResponse {
|
|||||||
nextCursor: number | null;
|
nextCursor: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RebuildLegacyMatchesResponse {
|
||||||
|
scanned: number;
|
||||||
|
rebuilt: number;
|
||||||
|
normalizedTitles: number;
|
||||||
|
skippedMissingRaw: number;
|
||||||
|
skippedNoKnownParticipants: number;
|
||||||
|
}
|
||||||
|
|
||||||
export type ApiRiotJobPriority = 'high' | 'low';
|
export type ApiRiotJobPriority = 'high' | 'low';
|
||||||
export type ApiRiotJobState = 'queued' | 'processing' | 'completed' | 'failed';
|
export type ApiRiotJobState = 'queued' | 'processing' | 'completed' | 'failed';
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
useDeleteMatch,
|
useDeleteMatch,
|
||||||
useLegacyMatches,
|
useLegacyMatches,
|
||||||
useMe,
|
useMe,
|
||||||
|
useRebuildLegacyMatches,
|
||||||
} from '../../api/hooks';
|
} from '../../api/hooks';
|
||||||
import type { LegacyMatchListItem } from '../../api/types';
|
import type { LegacyMatchListItem } from '../../api/types';
|
||||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||||
@@ -41,6 +42,7 @@ export default function LegacyMatchesPage() {
|
|||||||
const matchesQuery = useLegacyMatches(communityId, canManage);
|
const matchesQuery = useLegacyMatches(communityId, canManage);
|
||||||
const deleteMutation = useDeleteMatch(communityId);
|
const deleteMutation = useDeleteMatch(communityId);
|
||||||
const bulkDeleteMutation = useBulkDeleteLegacyMatches(communityId);
|
const bulkDeleteMutation = useBulkDeleteLegacyMatches(communityId);
|
||||||
|
const rebuildMutation = useRebuildLegacyMatches(communityId);
|
||||||
const matches = matchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
|
const matches = matchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
|
||||||
const selectedIds = useMemo(
|
const selectedIds = useMemo(
|
||||||
() => Object.entries(selected).filter(([, value]) => value).map(([id]) => id),
|
() => Object.entries(selected).filter(([, value]) => value).map(([id]) => id),
|
||||||
@@ -57,6 +59,9 @@ export default function LegacyMatchesPage() {
|
|||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ['community-internal-stats-leaderboard', communityId],
|
queryKey: ['community-internal-stats-leaderboard', communityId],
|
||||||
}),
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ['community-internal-stats-team-insights', communityId],
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +109,20 @@ export default function LegacyMatchesPage() {
|
|||||||
백필로 들어온 매치를 확인하고 외부 토너먼트 기록을 삭제할 수 있습니다.
|
백필로 들어온 매치를 확인하고 외부 토너먼트 기록을 삭제할 수 있습니다.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-primary btn-sm px-4 text-xs"
|
||||||
|
disabled={rebuildMutation.isPending}
|
||||||
|
onClick={() => {
|
||||||
|
if (!window.confirm('현재 가입자 기준으로 과거 매치를 재구성할까요?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rebuildMutation.mutate(undefined, { onSuccess: invalidate });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{rebuildMutation.isPending ? '재구성 중...' : '과거 데이터 재구성'}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-ghost btn-sm px-4 text-xs text-red-400"
|
className="btn btn-ghost btn-sm px-4 text-xs text-red-400"
|
||||||
@@ -121,6 +140,15 @@ export default function LegacyMatchesPage() {
|
|||||||
선택 삭제 ({selectedIds.length})
|
선택 삭제 ({selectedIds.length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{rebuildMutation.data && (
|
||||||
|
<div className="mb-4 border border-primary/20 bg-primary/5 px-3 py-2 text-xs text-base-content/55">
|
||||||
|
재구성 완료: {rebuildMutation.data.scanned}개 확인 ·{' '}
|
||||||
|
{rebuildMutation.data.rebuilt}개 갱신 · 제목 정리{' '}
|
||||||
|
{rebuildMutation.data.normalizedTitles}개
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
|
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
|
|||||||
Reference in new issue
Block a user