perf: optimize public event query by using lightweight session lookup (#23617)

* refactor event endpoint

* export getSessino
This commit is contained in:
Benny Joo
2025-09-06 09:42:27 -03:00
committed by GitHub
parent 7a1c780088
commit 29201006d5
2 changed files with 5 additions and 7 deletions
@@ -87,7 +87,7 @@ export async function getUserFromSession(ctx: TRPCContextInner, session: Maybe<S
export type UserFromSession = Awaited<ReturnType<typeof getUserFromSession>>;
const getSession = async (ctx: TRPCContextInner) => {
export const getSession = async (ctx: TRPCContextInner) => {
const { req } = ctx;
const { getServerSession } = await import("@calcom/features/auth/lib/getServerSession");
return req ? await getServerSession({ req }) : null;
@@ -1,12 +1,10 @@
import { getUserSession } from "../../../middlewares/sessionMiddleware";
import { getSession } from "../../../middlewares/sessionMiddleware";
import publicProcedure from "../../../procedures/publicProcedure";
import { ZEventInputSchema } from "../event.schema";
const NAMESPACE = "publicViewer";
const namespaced = (s: string) => `${NAMESPACE}.${s}`;
export const event = publicProcedure.input(ZEventInputSchema).query(async (opts) => {
const { user } = await getUserSession(opts.ctx);
const session = await getSession(opts.ctx);
const userId = session?.user?.id;
const { default: handler } = await import("../event.handler");
return handler({ input: opts.input, userId: user?.id });
return handler({ input: opts.input, userId });
});