perf: optimize public event query by using lightweight session lookup (#23617)
* refactor event endpoint * export getSessino
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user