fix reserved turn queue concurrency
This commit is contained in:
@@ -315,9 +315,7 @@ const upsertRankRows = async (
|
||||
await prisma.$executeRaw(GamePrisma.sql`
|
||||
INSERT INTO "rank_data" ("general_id", "nation_id", "type", "value")
|
||||
VALUES ${GamePrisma.join(
|
||||
batch.map(
|
||||
(row) => GamePrisma.sql`(${row.generalId}, ${row.nationId}, ${row.type}, ${row.value})`
|
||||
)
|
||||
batch.map((row) => GamePrisma.sql`(${row.generalId}, ${row.nationId}, ${row.type}, ${row.value})`)
|
||||
)}
|
||||
ON CONFLICT ("general_id", "type") DO UPDATE
|
||||
SET
|
||||
@@ -799,6 +797,11 @@ export const createDatabaseTurnHooks = async (
|
||||
}
|
||||
|
||||
if (deletedGenerals.length > 0) {
|
||||
if (prisma.generalTurnRevision) {
|
||||
await prisma.generalTurnRevision.deleteMany({
|
||||
where: { generalId: { in: deletedGenerals } },
|
||||
});
|
||||
}
|
||||
await prisma.generalTurn.deleteMany({
|
||||
where: { generalId: { in: deletedGenerals } },
|
||||
});
|
||||
@@ -816,6 +819,11 @@ export const createDatabaseTurnHooks = async (
|
||||
OR: [{ srcNationId: { in: deletedNations } }, { destNationId: { in: deletedNations } }],
|
||||
},
|
||||
});
|
||||
if (prisma.nationTurnRevision) {
|
||||
await prisma.nationTurnRevision.deleteMany({
|
||||
where: { nationId: { in: deletedNations } },
|
||||
});
|
||||
}
|
||||
await prisma.nationTurn.deleteMany({
|
||||
where: { nationId: { in: deletedNations } },
|
||||
});
|
||||
|
||||
@@ -70,7 +70,10 @@ const buildTurnListFromRows = (
|
||||
|
||||
const buildNationKey = (nationId: number, officerLevel: number): string => `${nationId}:${officerLevel}`;
|
||||
|
||||
type ReservedTurnDatabaseClient = Pick<TurnEngineDatabaseClient, 'generalTurn' | 'nationTurn'>;
|
||||
type ReservedTurnDatabaseClient = Pick<TurnEngineDatabaseClient, 'generalTurn' | 'nationTurn'> & {
|
||||
generalTurnRevision?: Pick<NonNullable<TurnEngineDatabaseClient['generalTurnRevision']>, 'upsert'>;
|
||||
nationTurnRevision?: Pick<NonNullable<TurnEngineDatabaseClient['nationTurnRevision']>, 'upsert'>;
|
||||
};
|
||||
|
||||
export interface ReservedTurnChanges {
|
||||
generalIds: number[];
|
||||
@@ -281,6 +284,13 @@ export class InMemoryReservedTurnStore {
|
||||
arg: asJson(normalizeArgs(entry.args)),
|
||||
})),
|
||||
});
|
||||
if (prisma.generalTurnRevision) {
|
||||
await prisma.generalTurnRevision.upsert({
|
||||
where: { generalId },
|
||||
create: { generalId, revision: 1 },
|
||||
update: { revision: { increment: 1 } },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const generalId of changes.generalInitializationIds) {
|
||||
@@ -316,6 +326,18 @@ export class InMemoryReservedTurnStore {
|
||||
arg: asJson(normalizeArgs(entry.args)),
|
||||
})),
|
||||
});
|
||||
if (prisma.nationTurnRevision) {
|
||||
await prisma.nationTurnRevision.upsert({
|
||||
where: {
|
||||
nationId_officerLevel: {
|
||||
nationId,
|
||||
officerLevel,
|
||||
},
|
||||
},
|
||||
create: { nationId, officerLevel, revision: 1 },
|
||||
update: { revision: { increment: 1 } },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of changes.nationInitializationKeys) {
|
||||
|
||||
Reference in New Issue
Block a user