perf: 접속 점수를 Redis 배치로 지연 반영
대시보드 벌점을 read-model source와 outbox에서 제외하고 수동 projection의 가점을 Redis에 합산한다. 5초 worker가 월별 traffic과 접속 점수를 멱등 PostgreSQL batch로 반영하며 메인 제한 gate는 Redis TTL marker만 조회한다.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { DatabaseClient } from '../src/context.js';
|
||||
import { readDashboardSourceRevisionState } from '../src/services/dashboardSourceRevision.js';
|
||||
import {
|
||||
readDashboardSourceRevisionState,
|
||||
readDashboardSourceRevisionStateForUser,
|
||||
} from '../src/services/dashboardSourceRevision.js';
|
||||
|
||||
const row = (overrides: Record<string, unknown> = {}) => ({
|
||||
generalId: 7,
|
||||
@@ -13,7 +16,6 @@ const row = (overrides: Record<string, unknown> = {}) => ({
|
||||
cityRevision: 12n,
|
||||
nationRevision: 13n,
|
||||
worldRevision: 14n,
|
||||
accessRevision: 15n,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
@@ -36,7 +38,6 @@ describe('dashboard source revision', () => {
|
||||
cityRevision: 0n,
|
||||
nationRevision: 0n,
|
||||
worldRevision: 0n,
|
||||
accessRevision: 0n,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -47,17 +48,16 @@ describe('dashboard source revision', () => {
|
||||
expect.stringMatching(/^[A-Za-z0-9_-]{22}$/u),
|
||||
]);
|
||||
const statement = queryRaw.mock.calls[0]?.[0] as { sql: string };
|
||||
expect(statement.sql.match(/COALESCE\([^)]*\."revision", 0\)/gu)).toHaveLength(6);
|
||||
expect(statement.sql.match(/COALESCE\([^)]*\."revision", 0\)/gu)).toHaveLength(5);
|
||||
});
|
||||
|
||||
it('hashes exactly the documented context, command, and board dependency vectors', async () => {
|
||||
const initial = (await read([row()])).state;
|
||||
const globalChanged = (await read([row({ globalRevision: 99n })])).state;
|
||||
const cityChanged = (await read([row({ cityRevision: 99n })])).state;
|
||||
const accessChanged = (await read([row({ accessRevision: 99n })])).state;
|
||||
const worldChanged = (await read([row({ worldRevision: 99n })])).state;
|
||||
const nationChanged = (await read([row({ nationRevision: 99n })])).state;
|
||||
if (!initial || !globalChanged || !cityChanged || !accessChanged || !worldChanged || !nationChanged) {
|
||||
if (!initial || !globalChanged || !cityChanged || !worldChanged || !nationChanged) {
|
||||
throw new Error('source revision state missing');
|
||||
}
|
||||
|
||||
@@ -67,9 +67,6 @@ describe('dashboard source revision', () => {
|
||||
expect(cityChanged.sourceRevisions.context).not.toBe(initial.sourceRevisions.context);
|
||||
expect(cityChanged.sourceRevisions.commandTable).not.toBe(initial.sourceRevisions.commandTable);
|
||||
expect(cityChanged.sourceRevisions.boardAccess).toBe(initial.sourceRevisions.boardAccess);
|
||||
expect(accessChanged.sourceRevisions.context).not.toBe(initial.sourceRevisions.context);
|
||||
expect(accessChanged.sourceRevisions.commandTable).toBe(initial.sourceRevisions.commandTable);
|
||||
expect(accessChanged.sourceRevisions.boardAccess).toBe(initial.sourceRevisions.boardAccess);
|
||||
expect(worldChanged.sourceRevisions.context).not.toBe(initial.sourceRevisions.context);
|
||||
expect(worldChanged.sourceRevisions.commandTable).not.toBe(initial.sourceRevisions.commandTable);
|
||||
expect(worldChanged.sourceRevisions.boardAccess).toBe(initial.sourceRevisions.boardAccess);
|
||||
@@ -78,6 +75,19 @@ describe('dashboard source revision', () => {
|
||||
expect(nationChanged.sourceRevisions.boardAccess).not.toBe(initial.sourceRevisions.boardAccess);
|
||||
});
|
||||
|
||||
it('resolves the authenticated actor and revision vector in one user-owned statement', async () => {
|
||||
const queryRaw = vi.fn(async (_query: unknown) => [row()]);
|
||||
await expect(
|
||||
readDashboardSourceRevisionStateForUser(
|
||||
{ $queryRaw: queryRaw } as Pick<DatabaseClient, '$queryRaw'>,
|
||||
'viewer-7'
|
||||
)
|
||||
).resolves.toMatchObject({ identity: { generalId: 7 } });
|
||||
const statement = queryRaw.mock.calls[0]?.[0] as { sql: string; values: unknown[] };
|
||||
expect(statement.sql).toContain('actor."user_id"');
|
||||
expect(statement.values).toContain('viewer-7');
|
||||
});
|
||||
|
||||
it('includes only the authenticated icon projection in the context source', async () => {
|
||||
const initial = (
|
||||
await read([row()], {
|
||||
|
||||
Reference in New Issue
Block a user