perf(game-api): 사령부 예약턴 조회를 일괄화한다

관직 8개의 턴과 revision을 16개 개별 query 대신 두 번의 findMany로 읽고 기존 응답 기본값을 회귀 검증한다.
This commit is contained in:
2026-08-21 23:17:32 +00:00
parent e67a40e51d
commit 7716b2cc7c
3 changed files with 89 additions and 5 deletions
+36
View File
@@ -218,6 +218,42 @@ export const getNationTurnSnapshot = async (
};
};
export const getNationTurnSnapshots = async (
db: DatabaseClient,
nationId: number,
officerLevels: readonly number[]
): Promise<Map<number, ReservedTurnSnapshot>> => {
const levels = [...new Set(officerLevels)];
if (levels.length === 0) return new Map();
const [turnRows, revisionRows] = await Promise.all([
db.nationTurn.findMany({
where: { nationId, officerLevel: { in: levels } },
orderBy: [{ officerLevel: 'asc' }, { turnIdx: 'asc' }],
}),
db.nationTurnRevision.findMany({
where: { nationId, officerLevel: { in: levels } },
}),
]);
const turnsByLevel = new Map<number, NationTurnRow[]>();
for (const row of turnRows) {
const rows = turnsByLevel.get(row.officerLevel) ?? [];
rows.push(row);
turnsByLevel.set(row.officerLevel, rows);
}
const revisionByLevel = new Map(revisionRows.map((row) => [row.officerLevel, row.revision]));
return new Map(
levels.map((level) => [
level,
{
revision: revisionByLevel.get(level) ?? 0,
turns: serializeTurnList(
buildTurnListFromRows(turnsByLevel.get(level) ?? [], MAX_NATION_TURNS)
),
},
])
);
};
const claimGeneralRevision = async (
db: DatabaseClient,
generalId: number,