perf: 실시간 접속 확인에서 불필요한 context 조회를 제거

This commit is contained in:
2026-08-16 17:53:25 +00:00
parent dd2ae20167
commit aa51f1b7d9
8 changed files with 148 additions and 78 deletions
+29 -22
View File
@@ -9,26 +9,21 @@ import { getTurnCommandTable } from '../turns/index.js';
const zRevision = z.string().regex(/^[A-Za-z0-9_-]{22}$/u);
const zContextBundleInput = z
.object({
include: z.object({
context: z.boolean(),
commandTable: z.boolean(),
boardAccess: z.boolean(),
}),
known: z
.object({
context: zRevision.optional(),
commandTable: zRevision.optional(),
boardAccess: zRevision.optional(),
})
.optional(),
forceSnapshot: z.boolean().optional(),
})
.refine((input) => Object.values(input.include).some(Boolean), {
message: 'At least one dashboard context slice must be requested.',
path: ['include'],
});
const zContextBundleInput = z.object({
include: z.object({
context: z.boolean(),
commandTable: z.boolean(),
boardAccess: z.boolean(),
}),
known: z
.object({
context: zRevision.optional(),
commandTable: zRevision.optional(),
boardAccess: zRevision.optional(),
})
.optional(),
forceSnapshot: z.boolean().optional(),
});
export const dashboardRouter = router({
getContextBundleDelta: accessLimitAuthedProcedure.input(zContextBundleInput).query(async ({ ctx, input }) => {
@@ -37,8 +32,20 @@ export const dashboardRouter = router({
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
const currentContext = await getGeneralContext(ctx);
const generalId = currentContext?.general.id ?? null;
const includesProjection = Object.values(input.include).some(Boolean);
const currentContext = input.include.context ? await getGeneralContext(ctx) : undefined;
const generalId =
currentContext?.general.id ??
ctx.realtimeAccessGeneralId ??
(includesProjection
? (
await ctx.db.general.findFirst({
where: { userId: viewerId },
orderBy: { id: 'asc' },
select: { id: true },
})
)?.id ?? null
: null);
const [commandTable, boardAccess] = await Promise.all([
input.include.commandTable && generalId ? getTurnCommandTable(ctx, generalId) : Promise.resolve(undefined),
input.include.boardAccess && generalId ? getBoardAccess(ctx) : Promise.resolve(undefined),