fix: 지난 플레이 전투 자료를 보존한다

통일·장수 삭제·게임 취소 archive에 전투 집계와 숙련도, 전투 결과를 저장한다. 개인 기록과 전투 상세는 보존 대상에서 제외하고 기존 Core snapshot도 정규화한다.
This commit is contained in:
2026-08-22 09:15:45 +00:00
parent d74a8e48bb
commit d3d89cf003
12 changed files with 484 additions and 78 deletions
@@ -531,29 +531,44 @@ export const persistUnificationFinalization = async (
});
const archiveGenerals = [...neutralGenerals, ...winnerGenerals];
const generalHistoryRows = archiveGenerals.length
const generalRecordRows = archiveGenerals.length
? await transaction.logEntry.findMany({
where: {
generalId: { in: archiveGenerals.map((general) => general.id) },
scope: LogScope.GENERAL,
category: LogCategory.HISTORY,
category: { in: [LogCategory.HISTORY, LogCategory.BATTLE_BRIEF] },
},
orderBy: { id: 'asc' },
select: { generalId: true, text: true },
select: { generalId: true, category: true, text: true },
})
: [];
const historyByGeneral = new Map<number, string[]>();
for (const row of generalHistoryRows) {
const battleResultsByGeneral = new Map<number, string[]>();
for (const row of generalRecordRows) {
if (row.generalId === null) continue;
const history = historyByGeneral.get(row.generalId) ?? [];
history.push(row.text);
historyByGeneral.set(row.generalId, history);
const target =
row.category === LogCategory.HISTORY
? historyByGeneral
: row.category === LogCategory.BATTLE_BRIEF
? battleResultsByGeneral
: null;
if (!target) continue;
const records = target.get(row.generalId) ?? [];
records.push(row.text);
target.set(row.generalId, records);
}
for (const general of archiveGenerals) {
const ranks = ranksByGeneral.get(general.id) ?? {};
const data = {
...general,
meta: {
...asRecord(general.meta),
...Object.fromEntries(Object.entries(ranks).map(([key, value]) => [`rank_${key}`, value])),
},
turnTime: general.turnTime.toISOString(),
history: historyByGeneral.get(general.id) ?? [],
records: { battleResult: [...(battleResultsByGeneral.get(general.id) ?? [])].reverse() },
availability: { battleResultLogs: true },
generationKey: input.generationKey,
};
await transaction.oldGeneral.upsert({