fix: 외교 메시지의 시계 fallback과 fixture 경계를 복원한다

This commit is contained in:
2026-08-24 19:48:38 +00:00
parent 04101ba862
commit 97b7c49070
3 changed files with 108 additions and 22 deletions
+19 -18
View File
@@ -1,9 +1,9 @@
import { enqueuePrivateMessageWebPush, GamePrisma } from '@sammo-ts/infra';
import { MAX_SAFE_GAME_TICK } from '@sammo-ts/common';
import { enqueuePrivateMessageWebPush, GamePrisma } from '@sammo-ts/infra';
import type { MessagePayload, MessageRecordDraft, MessageType } from '@sammo-ts/logic';
import type { DatabaseClient } from '../context.js';
import { loadCurrentGameTime } from '../services/gameClock.js';
import { loadCurrentGameTime, type CurrentGameTime } from '../services/gameClock.js';
export interface MessageView {
id: number;
@@ -48,6 +48,19 @@ const formatMessageTime = (value: Date): string => {
)} ${pad(value.getHours())}:${pad(value.getMinutes())}:${pad(value.getSeconds())}`;
};
const messageValidityPredicate = (gameTime: CurrentGameTime) => {
if (gameTime.tick === null) {
// A legacy or partially migrated profile has no authoritative logical
// tick. Rows that already carry a tick still need the wall-time
// fallback used by the clock migration.
return GamePrisma.sql`valid_until > ${gameTime.now}`;
}
return GamePrisma.sql`(
(valid_until_tick IS NOT NULL AND valid_until_tick > ${BigInt(gameTime.tick)})
OR (valid_until_tick IS NULL AND valid_until > ${gameTime.now})
)`;
};
const toMessageView = (row: MessageRow): MessageView => {
const payload = parsePayload(row.message);
return {
@@ -113,10 +126,7 @@ export const fetchMessagesFromMailbox = async (params: {
FROM message
WHERE mailbox = ${params.mailbox}
AND type = ${params.msgType}
AND (
(valid_until_tick IS NOT NULL AND valid_until_tick > ${gameTime.tick === null ? null : BigInt(gameTime.tick)})
OR (valid_until_tick IS NULL AND valid_until > ${gameTime.now})
)
AND ${messageValidityPredicate(gameTime)}
AND id >= ${fromSeq}
ORDER BY id DESC
LIMIT ${params.limit}
@@ -138,10 +148,7 @@ export const fetchOldMessagesFromMailbox = async (params: {
FROM message
WHERE mailbox = ${params.mailbox}
AND type = ${params.msgType}
AND (
(valid_until_tick IS NOT NULL AND valid_until_tick > ${gameTime.tick === null ? null : BigInt(gameTime.tick)})
OR (valid_until_tick IS NULL AND valid_until > ${gameTime.now})
)
AND ${messageValidityPredicate(gameTime)}
AND id < ${params.toSeq}
ORDER BY id DESC
LIMIT ${params.limit}
@@ -156,10 +163,7 @@ export const fetchMessageById = async (db: DatabaseClient, id: number): Promise<
SELECT id, mailbox, type, src, dest, time, valid_until, message
FROM message
WHERE id = ${id}
AND (
(valid_until_tick IS NOT NULL AND valid_until_tick > ${gameTime.tick === null ? null : BigInt(gameTime.tick)})
OR (valid_until_tick IS NULL AND valid_until > ${gameTime.now})
)
AND ${messageValidityPredicate(gameTime)}
LIMIT 1
`;
const row = rows[0];
@@ -179,10 +183,7 @@ export const fetchMessageByIdForUpdate = async (db: DatabaseClient, id: number):
SELECT id, mailbox, type, src, dest, time, valid_until, message
FROM message
WHERE id = ${id}
AND (
(valid_until_tick IS NOT NULL AND valid_until_tick > ${gameTime.tick === null ? null : BigInt(gameTime.tick)})
OR (valid_until_tick IS NULL AND valid_until > ${gameTime.now})
)
AND ${messageValidityPredicate(gameTime)}
LIMIT 1
FOR UPDATE
`;