갱신 행의 ID를 보존하고 예약턴의 불필요한 시퀀스를 제거한다
This commit is contained in:
1 parent
bc54b157c1
commit
81e101ffef
43 files changed
+587
-113
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { upsertWithoutSequence } from '@sammo-ts/infra';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { CLOCK_OPERATION_PERSISTENCE_LOCK, GamePrisma, acquireGameSchemaAdvisoryXactLock } from '@sammo-ts/infra';
|
||||
import { z } from 'zod';
|
||||
@@ -223,7 +224,7 @@ export const bettingRouter = router({
|
||||
world.currentMonth,
|
||||
`${input.amount} 포인트를 베팅에 사용`
|
||||
);
|
||||
await ctx.db.rankData.upsert({
|
||||
await upsertWithoutSequence(ctx.db.rankData, {
|
||||
where: {
|
||||
generalId_type: {
|
||||
generalId: general.id,
|
||||
@@ -245,7 +246,7 @@ export const bettingRouter = router({
|
||||
});
|
||||
}
|
||||
|
||||
await ctx.db.nationBet.upsert({
|
||||
await upsertWithoutSequence(ctx.db.nationBet, {
|
||||
where: {
|
||||
bettingId_userId_selectionKey: {
|
||||
bettingId: input.bettingId,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { existingRowIdOrNext } from '@sammo-ts/infra';
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
|
||||
import { asRecord, resolveAccessLimitLevel, resolveAccessRefreshLimit } from '@sammo-ts/common';
|
||||
@@ -94,7 +95,13 @@ export const enqueueDeferredGeneralAccess = async (
|
||||
}
|
||||
await redis.eval(ENQUEUE_SCRIPT, {
|
||||
keys: [activeKey(profileName)],
|
||||
arguments: [String(generalId), auth.user.id, String(weight), String(now.getTime()), String(ACTIVE_BATCH_TTL_MS)],
|
||||
arguments: [
|
||||
String(generalId),
|
||||
auth.user.id,
|
||||
String(weight),
|
||||
String(now.getTime()),
|
||||
String(ACTIVE_BATCH_TTL_MS),
|
||||
],
|
||||
});
|
||||
return true;
|
||||
};
|
||||
@@ -258,9 +265,10 @@ export const flushDeferredGeneralAccessBatch = async (
|
||||
),
|
||||
missing_periods AS (
|
||||
INSERT INTO "traffic_period" (
|
||||
"world_state_id", "year", "month", "started_at", "last_refresh", "refresh", "online"
|
||||
"id", "world_state_id", "year", "month", "started_at", "last_refresh", "refresh", "online"
|
||||
)
|
||||
SELECT
|
||||
${existingRowIdOrNext('traffic_period', GamePrisma.sql`stable_id.world_state_id = ${worldState.id} AND stable_id.year = (missing_key / 12)::INTEGER AND stable_id.month = (missing_key % 12 + 1)::INTEGER`)},
|
||||
${worldState.id},
|
||||
(missing_key / 12)::INTEGER,
|
||||
(missing_key % 12 + 1)::INTEGER,
|
||||
@@ -281,9 +289,10 @@ export const flushDeferredGeneralAccessBatch = async (
|
||||
),
|
||||
period_upsert AS (
|
||||
INSERT INTO "traffic_period" (
|
||||
"world_state_id", "year", "month", "started_at", "last_refresh", "refresh", "online"
|
||||
"id", "world_state_id", "year", "month", "started_at", "last_refresh", "refresh", "online"
|
||||
)
|
||||
SELECT
|
||||
${existingRowIdOrNext('traffic_period', GamePrisma.sql`stable_id.world_state_id = ${worldState.id} AND stable_id.year = ${worldState.currentYear} AND stable_id.month = ${worldState.currentMonth}`)},
|
||||
${worldState.id},
|
||||
${worldState.currentYear},
|
||||
${worldState.currentMonth},
|
||||
@@ -343,10 +352,11 @@ export const flushDeferredGeneralAccessBatch = async (
|
||||
),
|
||||
access_updates AS (
|
||||
INSERT INTO "general_access_log" (
|
||||
"general_id", "user_id", "last_refresh", "refresh", "refresh_total",
|
||||
"id", "general_id", "user_id", "last_refresh", "refresh", "refresh_total",
|
||||
"refresh_score", "refresh_score_total"
|
||||
)
|
||||
SELECT
|
||||
${existingRowIdOrNext('general_access_log', GamePrisma.sql`stable_id.general_id = resolved."general_id"`)},
|
||||
resolved."general_id",
|
||||
resolved."user_id",
|
||||
resolved."last_refresh",
|
||||
@@ -471,11 +481,9 @@ export class DeferredGeneralAccessWorker {
|
||||
await this.redis.del(key);
|
||||
return;
|
||||
}
|
||||
await this.redis.set(
|
||||
key,
|
||||
JSON.stringify({ nextAccessAt: state.nextAccessAt.toISOString() }),
|
||||
{ PX: Math.max(1, state.nextAccessAt.getTime() - now.getTime()) }
|
||||
);
|
||||
await this.redis.set(key, JSON.stringify({ nextAccessAt: state.nextAccessAt.toISOString() }), {
|
||||
PX: Math.max(1, state.nextAccessAt.getTime() - now.getTime()),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { existingRowIdOrNext } from '@sammo-ts/infra';
|
||||
import { asRecord, resolveAccessLimitLevel, resolveAccessRefreshLimit, type AccessLimitLevel } from '@sammo-ts/common';
|
||||
import { acquireGameSchemaAdvisoryXactLock, GENERAL_ACCESS_PERSISTENCE_LOCK, GamePrisma } from '@sammo-ts/infra';
|
||||
|
||||
@@ -269,6 +270,7 @@ export const upsertGeneralAccess = async (
|
||||
RETURNING id
|
||||
)
|
||||
INSERT INTO traffic_period (
|
||||
id,
|
||||
world_state_id,
|
||||
year,
|
||||
month,
|
||||
@@ -277,6 +279,7 @@ export const upsertGeneralAccess = async (
|
||||
refresh
|
||||
)
|
||||
VALUES (
|
||||
${existingRowIdOrNext('traffic_period', GamePrisma.sql`stable_id.world_state_id = ${input.worldStateId} AND stable_id.year = ${input.year} AND stable_id.month = ${input.month}`)},
|
||||
${input.worldStateId},
|
||||
${input.year},
|
||||
${input.month},
|
||||
@@ -341,6 +344,7 @@ export const upsertGeneralAccess = async (
|
||||
await transaction.$executeRaw(
|
||||
GamePrisma.sql`
|
||||
INSERT INTO general_access_log (
|
||||
id,
|
||||
general_id,
|
||||
user_id,
|
||||
last_refresh,
|
||||
@@ -350,6 +354,7 @@ export const upsertGeneralAccess = async (
|
||||
refresh_score_total
|
||||
)
|
||||
VALUES (
|
||||
${existingRowIdOrNext('general_access_log', GamePrisma.sql`stable_id.general_id = ${input.generalId}`)},
|
||||
${input.generalId},
|
||||
${input.userId},
|
||||
${input.now},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { existingRowIdOrNext } from '@sammo-ts/infra';
|
||||
import { GamePrisma } from '@sammo-ts/infra';
|
||||
|
||||
import type { GameApiContext } from '../context.js';
|
||||
@@ -20,11 +21,13 @@ export const recordGeneralActivity = async (
|
||||
const written = await ctx.db.$executeRaw(
|
||||
GamePrisma.sql`
|
||||
INSERT INTO general_access_log (
|
||||
id,
|
||||
general_id,
|
||||
user_id,
|
||||
last_action_at
|
||||
)
|
||||
SELECT
|
||||
${existingRowIdOrNext('general_access_log', GamePrisma.sql`stable_id.general_id = "general".id`)},
|
||||
id,
|
||||
${user.id},
|
||||
${now}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { upsertWithoutSequence } from '@sammo-ts/infra';
|
||||
import { asNumber, asRecord } from '@sammo-ts/common';
|
||||
import { GamePrisma } from '@sammo-ts/infra';
|
||||
import {
|
||||
@@ -132,7 +133,7 @@ export const setInheritancePoint = async (
|
||||
key: InheritPointKey,
|
||||
value: number
|
||||
): Promise<void> => {
|
||||
await db.inheritancePoint.upsert({
|
||||
await upsertWithoutSequence(db.inheritancePoint, {
|
||||
where: {
|
||||
userId_key: {
|
||||
userId,
|
||||
|
||||
Reference in new issue
Block a user