고빈도 저장 ID를 64비트로 확장하고 랭킹 갱신의 시퀀스 낭비를 막는다
This commit is contained in:
1 parent
087517821e
commit
bc54b157c1
25 files changed
+518
-86
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { toSafeInteger } from '@sammo-ts/common';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -281,7 +282,7 @@ export const auctionRouter = router({
|
||||
callerAlias,
|
||||
remainPoint: point?.value ?? 0,
|
||||
recentLogs: recentLogs.map((log) => ({
|
||||
id: log.id,
|
||||
id: toSafeInteger(log.id),
|
||||
text: log.text,
|
||||
createdAt: log.createdAt.toISOString(),
|
||||
})),
|
||||
@@ -444,7 +445,10 @@ export const auctionRouter = router({
|
||||
const timerKeys = buildAuctionTimerKeys(ctx.profile.name);
|
||||
const nextCloseAt = new Date(result.closeAt);
|
||||
await ctx.redis.zAdd(timerKeys.timerKey, [
|
||||
{ score: resolveAuctionTimerScore(gameTime, nextCloseAt, BigInt(result.closeTick)), value: String(auction.id) },
|
||||
{
|
||||
score: resolveAuctionTimerScore(gameTime, nextCloseAt, BigInt(result.closeTick)),
|
||||
value: String(auction.id),
|
||||
},
|
||||
]);
|
||||
|
||||
return { ok: true };
|
||||
@@ -521,7 +525,10 @@ export const auctionRouter = router({
|
||||
const timerKeys = buildAuctionTimerKeys(ctx.profile.name);
|
||||
const nextCloseAt = new Date(result.closeAt);
|
||||
await ctx.redis.zAdd(timerKeys.timerKey, [
|
||||
{ score: resolveAuctionTimerScore(gameTime, nextCloseAt, BigInt(result.closeTick)), value: String(auction.id) },
|
||||
{
|
||||
score: resolveAuctionTimerScore(gameTime, nextCloseAt, BigInt(result.closeTick)),
|
||||
value: String(auction.id),
|
||||
},
|
||||
]);
|
||||
|
||||
return { ok: true };
|
||||
@@ -659,7 +666,10 @@ export const auctionRouter = router({
|
||||
const timerKeys = buildAuctionTimerKeys(ctx.profile.name);
|
||||
const nextCloseAt = new Date(result.closeAt);
|
||||
await ctx.redis.zAdd(timerKeys.timerKey, [
|
||||
{ score: resolveAuctionTimerScore(gameTime, nextCloseAt, BigInt(result.closeTick)), value: String(auction.id) },
|
||||
{
|
||||
score: resolveAuctionTimerScore(gameTime, nextCloseAt, BigInt(result.closeTick)),
|
||||
value: String(auction.id),
|
||||
},
|
||||
]);
|
||||
|
||||
return { ok: true };
|
||||
|
||||
@@ -2,7 +2,7 @@ import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getBillByLevel, LogCategory, LogScope } from '@sammo-ts/logic';
|
||||
import { asRecord, readOfficeRequest, type RankDataType } from '@sammo-ts/common';
|
||||
import { asRecord, readOfficeRequest, toSafeInteger, withSafeIntegerId, type RankDataType } from '@sammo-ts/common';
|
||||
|
||||
import type { GameApiContext } from '../../context.js';
|
||||
import {
|
||||
@@ -588,10 +588,7 @@ export const getGeneralContext = async (ctx: GameApiContext) => {
|
||||
recentWar: general.recentWarTime?.toISOString() ?? null,
|
||||
defenceTrain: settings.defence_train,
|
||||
killTurn: readNumber(metaRecord.killturn ?? metaRecord.killTurn, 0),
|
||||
remainingMinutes: resolveRemainingMinutes(
|
||||
general.turnTime,
|
||||
gameTime.now
|
||||
),
|
||||
remainingMinutes: resolveRemainingMinutes(general.turnTime, gameTime.now),
|
||||
crewTypeId: general.crewTypeId,
|
||||
crewTypeName: crewTypeDetails.get(general.crewTypeId)?.name ?? '-',
|
||||
crewTypeInfo: crewTypeDetails.get(general.crewTypeId) ?? null,
|
||||
@@ -916,7 +913,7 @@ export const generalRouter = router({
|
||||
return {
|
||||
type: input.type,
|
||||
logs: logs.map((entry) => ({
|
||||
id: entry.id,
|
||||
id: toSafeInteger(entry.id),
|
||||
text: entry.text,
|
||||
})),
|
||||
};
|
||||
@@ -966,9 +963,9 @@ export const generalRouter = router({
|
||||
]);
|
||||
|
||||
return {
|
||||
global: trimRecentRecords(global, input.lastGeneralRecordId),
|
||||
general: trimRecentRecords(general, input.lastGeneralRecordId),
|
||||
history: trimRecentRecords(history, input.lastWorldHistoryId),
|
||||
global: trimRecentRecords(global.map(withSafeIntegerId), input.lastGeneralRecordId),
|
||||
general: trimRecentRecords(general.map(withSafeIntegerId), input.lastGeneralRecordId),
|
||||
history: trimRecentRecords(history.map(withSafeIntegerId), input.lastWorldHistoryId),
|
||||
};
|
||||
}),
|
||||
// 메인 화면은 SSE invalidation, 탭 복귀와 직접 갱신이 같은 read model을
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { withSafeIntegerId } from '@sammo-ts/common';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -38,7 +39,6 @@ const BUFF_KEYS: InheritBuffType[] = [
|
||||
|
||||
const UNIQUE_ITEM_SLOT_ORDER: readonly ItemSlot[] = ['horse', 'weapon', 'book', 'item'];
|
||||
|
||||
const POSTGRES_INTEGER_MAX = 2_147_483_647;
|
||||
const MIN_INHERIT_BUFF_LEVEL = 1;
|
||||
const MAX_INHERIT_BUFF_LEVEL = 5;
|
||||
|
||||
@@ -283,7 +283,7 @@ export const inheritRouter = router({
|
||||
getLogs: authedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
lastId: z.number().int().min(1).max(POSTGRES_INTEGER_MAX).optional(),
|
||||
lastId: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional(),
|
||||
})
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
@@ -300,7 +300,7 @@ export const inheritRouter = router({
|
||||
take: 30,
|
||||
select: { id: true, year: true, month: true, text: true, createdAt: true },
|
||||
});
|
||||
return logs;
|
||||
return logs.map(withSafeIntegerId);
|
||||
}),
|
||||
buyHiddenBuff: engineAuthedProcedure
|
||||
.input(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { toSafeInteger } from '@sammo-ts/common';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -77,7 +78,7 @@ export const getGeneralLog = accessLimitAuthedInputProcedure(
|
||||
type: input.type,
|
||||
generalId: target.id,
|
||||
logs: logs.map((entry) => ({
|
||||
id: entry.id,
|
||||
id: toSafeInteger(entry.id),
|
||||
text: entry.text,
|
||||
year: entry.year,
|
||||
month: entry.month,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { withSafeIntegerId } from '@sammo-ts/common';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
|
||||
import { asRecord } from '@sammo-ts/common';
|
||||
@@ -129,6 +130,6 @@ export const getNationInfo = authedProcedure.query(async ({ ctx }) => {
|
||||
name: city.name,
|
||||
capital: city.id === nation.capitalCityId,
|
||||
})),
|
||||
history,
|
||||
history: history.map(withSafeIntegerId),
|
||||
};
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { toSafeInteger, withSafeIntegerId } from '@sammo-ts/common';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
import { auditProcedure, monthOrdinal, readAudit, readAuditWorld } from './shared.js';
|
||||
@@ -53,8 +54,8 @@ export const generalLogs = auditProcedure
|
||||
...world,
|
||||
type: input.type,
|
||||
coverage: world.serverId ? ('IDENTIFIED_LOGS_ONLY' as const) : ('IDENTITY_MISSING' as const),
|
||||
items: rows.slice(0, input.limit),
|
||||
nextCursor: rows.length > input.limit ? rows[input.limit - 1]!.id : null,
|
||||
items: rows.slice(0, input.limit).map(withSafeIntegerId),
|
||||
nextCursor: rows.length > input.limit ? toSafeInteger(rows[input.limit - 1]!.id) : null,
|
||||
};
|
||||
})
|
||||
);
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { asNumber, asRecord } from '@sammo-ts/common';
|
||||
import { asNumber, asRecord, withSafeIntegerId } from '@sammo-ts/common';
|
||||
import { LEGACY_DEFAULT_MAX_LEVEL, LogCategory, LogScope } from '@sammo-ts/logic';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -306,7 +306,7 @@ export const publicRouter = router({
|
||||
}
|
||||
const snapshot = {
|
||||
...map,
|
||||
history,
|
||||
history: history.map(withSafeIntegerId),
|
||||
};
|
||||
await ctx.redis.set(cacheKey, JSON.stringify(snapshot), { EX: PUBLIC_CACHE_TTL_SECONDS });
|
||||
return snapshot;
|
||||
|
||||
@@ -230,7 +230,7 @@ export const upsertGeneralAccess = async (
|
||||
await db.$transaction(async (transaction) => {
|
||||
await acquireGameSchemaAdvisoryXactLock(transaction, GENERAL_ACCESS_PERSISTENCE_LOCK);
|
||||
const periodKey = input.year * 12 + input.month - 1;
|
||||
const periodRows = await transaction.$queryRaw<Array<{ id: number }>>(
|
||||
const periodRows = await transaction.$queryRaw<Array<{ id: bigint }>>(
|
||||
GamePrisma.sql`
|
||||
WITH latest_period AS (
|
||||
SELECT MAX(year * 12 + month - 1)::INTEGER AS period_key
|
||||
|
||||
Reference in new issue
Block a user