perf: Move apps procedures off of loggedInViewer (#20112)
* perf: Slim down loggedInViewer tRPC router * Fixed trpc client calls for new routes * Moved bookingUnconfirmedCount * Moved getUserTopBanners to me router * Moved shouldVerifyEmail to me router * Moved i18n from public to its own router * fix ssrInit * fix ssrInit usage * fix type check * better naming * fix * fix * Fix types * Removed used of importHandler * perf: Move apps procedures off of loggedInViewer * Moved 2 more apps-related procedures --------- Co-authored-by: hbjORbj <[email protected]>
This commit is contained in:
1 parent
3be9e1bd38
commit
30dce7bacd
53 files changed
+209
-182
No files matched your search
@@ -2,15 +2,12 @@ import authedProcedure from "../../procedures/authedProcedure";
|
||||
import { importHandler, router } from "../../trpc";
|
||||
import { ZAddNotificationsSubscriptionInputSchema } from "./addNotificationsSubscription.schema";
|
||||
import { ZAddSecondaryEmailInputSchema } from "./addSecondaryEmail.schema";
|
||||
import { ZAppByIdInputSchema } from "./appById.schema";
|
||||
import { ZAppCredentialsByTypeInputSchema } from "./appCredentialsByType.schema";
|
||||
import { ZConnectAndJoinInputSchema } from "./connectAndJoin.schema";
|
||||
import { ZConnectedCalendarsInputSchema } from "./connectedCalendars.schema";
|
||||
import { ZDeleteCredentialInputSchema } from "./deleteCredential.schema";
|
||||
import { ZEventTypeOrderInputSchema } from "./eventTypeOrder.schema";
|
||||
import { ZGetCalVideoRecordingsInputSchema } from "./getCalVideoRecordings.schema";
|
||||
import { ZGetDownloadLinkOfCalVideoRecordingsInputSchema } from "./getDownloadLinkOfCalVideoRecordings.schema";
|
||||
import { ZIntegrationsInputSchema } from "./integrations.schema";
|
||||
import { ZLocationOptionsInputSchema } from "./locationOptions.schema";
|
||||
import { ZNoShowInputSchema } from "./markNoShow.schema";
|
||||
import { ZOutOfOfficeInputSchema } from "./outOfOfficeCreateOrUpdate.schema";
|
||||
@@ -22,7 +19,6 @@ import { ZRoutingFormOrderInputSchema } from "./routingFormOrder.schema";
|
||||
import { ZSetDestinationCalendarInputSchema } from "./setDestinationCalendar.schema";
|
||||
import { ZSubmitFeedbackInputSchema } from "./submitFeedback.schema";
|
||||
import { ZUpdateProfileInputSchema } from "./updateProfile.schema";
|
||||
import { ZUpdateUserDefaultConferencingAppInputSchema } from "./updateUserDefaultConferencingApp.schema";
|
||||
import { ZWorkflowOrderInputSchema } from "./workflowOrder.schema";
|
||||
|
||||
const NAMESPACE = "loggedInViewer";
|
||||
@@ -32,9 +28,6 @@ const namespaced = (s: string) => `${NAMESPACE}.${s}`;
|
||||
type AppsRouterHandlerCache = {
|
||||
connectedCalendars?: typeof import("./connectedCalendars.handler").connectedCalendarsHandler;
|
||||
setDestinationCalendar?: typeof import("./setDestinationCalendar.handler").setDestinationCalendarHandler;
|
||||
integrations?: typeof import("./integrations.handler").integrationsHandler;
|
||||
appById?: typeof import("./appById.handler").appByIdHandler;
|
||||
appCredentialsByType?: typeof import("./appCredentialsByType.handler").appCredentialsByTypeHandler;
|
||||
stripeCustomer?: typeof import("./stripeCustomer.handler").stripeCustomerHandler;
|
||||
updateProfile?: typeof import("./updateProfile.handler").updateProfileHandler;
|
||||
eventTypeOrder?: typeof import("./eventTypeOrder.handler").eventTypeOrderHandler;
|
||||
@@ -45,8 +38,6 @@ type AppsRouterHandlerCache = {
|
||||
deleteCredential?: typeof import("./deleteCredential.handler").deleteCredentialHandler;
|
||||
getCalVideoRecordings?: typeof import("./getCalVideoRecordings.handler").getCalVideoRecordingsHandler;
|
||||
getDownloadLinkOfCalVideoRecordings?: typeof import("./getDownloadLinkOfCalVideoRecordings.handler").getDownloadLinkOfCalVideoRecordingsHandler;
|
||||
getUsersDefaultConferencingApp?: typeof import("./getUsersDefaultConferencingApp.handler").getUsersDefaultConferencingAppHandler;
|
||||
updateUserDefaultConferencingApp?: typeof import("./updateUserDefaultConferencingApp.handler").updateUserDefaultConferencingAppHandler;
|
||||
teamsAndUserProfilesQuery?: typeof import("./teamsAndUserProfilesQuery.handler").teamsAndUserProfilesQuery;
|
||||
connectAndJoin?: typeof import("./connectAndJoin.handler").Handler;
|
||||
outOfOfficeCreateOrUpdate?: typeof import("./outOfOfficeCreateOrUpdate.handler").outOfOfficeCreateOrUpdate;
|
||||
@@ -95,49 +86,6 @@ export const loggedInViewerRouter = router({
|
||||
return UNSTABLE_HANDLER_CACHE.setDestinationCalendar({ ctx, input });
|
||||
}),
|
||||
|
||||
integrations: authedProcedure.input(ZIntegrationsInputSchema).query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.integrations) {
|
||||
UNSTABLE_HANDLER_CACHE.integrations = (await import("./integrations.handler")).integrationsHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.integrations) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.integrations({ ctx, input });
|
||||
}),
|
||||
|
||||
appById: authedProcedure.input(ZAppByIdInputSchema).query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.appById) {
|
||||
UNSTABLE_HANDLER_CACHE.appById = (await import("./appById.handler")).appByIdHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.appById) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.appById({ ctx, input });
|
||||
}),
|
||||
|
||||
appCredentialsByType: authedProcedure
|
||||
.input(ZAppCredentialsByTypeInputSchema)
|
||||
.query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.appCredentialsByType) {
|
||||
UNSTABLE_HANDLER_CACHE.appCredentialsByType = (
|
||||
await import("./appCredentialsByType.handler")
|
||||
).appCredentialsByTypeHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.appCredentialsByType) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.appCredentialsByType({ ctx, input });
|
||||
}),
|
||||
|
||||
stripeCustomer: authedProcedure.query(async ({ ctx }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.stripeCustomer) {
|
||||
UNSTABLE_HANDLER_CACHE.stripeCustomer = (
|
||||
@@ -296,38 +244,6 @@ export const loggedInViewerRouter = router({
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.getDownloadLinkOfCalVideoRecordings({ ctx, input });
|
||||
}),
|
||||
|
||||
getUsersDefaultConferencingApp: authedProcedure.query(async ({ ctx }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp) {
|
||||
UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp = (
|
||||
await import("./getUsersDefaultConferencingApp.handler")
|
||||
).getUsersDefaultConferencingAppHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp({ ctx });
|
||||
}),
|
||||
|
||||
updateUserDefaultConferencingApp: authedProcedure
|
||||
.input(ZUpdateUserDefaultConferencingAppInputSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp) {
|
||||
UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp = (
|
||||
await import("./updateUserDefaultConferencingApp.handler")
|
||||
).updateUserDefaultConferencingAppHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp({ ctx, input });
|
||||
}),
|
||||
teamsAndUserProfilesQuery,
|
||||
connectAndJoin: authedProcedure.input(ZConnectAndJoinInputSchema).mutation(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.connectAndJoin) {
|
||||
|
||||
@@ -37,6 +37,7 @@ export const viewerRouter = mergeRouters(
|
||||
loggedInViewerRouter,
|
||||
|
||||
router({
|
||||
apps: appsRouter,
|
||||
me: meRouter,
|
||||
public: publicViewerRouter,
|
||||
auth: authRouter,
|
||||
@@ -62,7 +63,6 @@ export const viewerRouter = mergeRouters(
|
||||
appRoutingForms: app_RoutingForms,
|
||||
appBasecamp3: app_Basecamp3,
|
||||
features: featureFlagRouter,
|
||||
appsRouter,
|
||||
users: userAdminRouter,
|
||||
oAuth: oAuthRouter,
|
||||
googleWorkspace: googleWorkspaceRouter,
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import authedProcedure, { authedAdminProcedure } from "../../../procedures/authedProcedure";
|
||||
import { router } from "../../../trpc";
|
||||
import { ZAppByIdInputSchema } from "./appById.schema";
|
||||
import { ZAppCredentialsByTypeInputSchema } from "./appCredentialsByType.schema";
|
||||
import { checkGlobalKeysSchema } from "./checkGlobalKeys.schema";
|
||||
import { ZIntegrationsInputSchema } from "./integrations.schema";
|
||||
import { ZListLocalInputSchema } from "./listLocal.schema";
|
||||
import { ZQueryForDependenciesInputSchema } from "./queryForDependencies.schema";
|
||||
import { ZSaveKeysInputSchema } from "./saveKeys.schema";
|
||||
import { ZSetDefaultConferencingAppSchema } from "./setDefaultConferencingApp.schema";
|
||||
import { ZToggleInputSchema } from "./toggle.schema";
|
||||
import { ZUpdateAppCredentialsInputSchema } from "./updateAppCredentials.schema";
|
||||
import { ZUpdateUserDefaultConferencingAppInputSchema } from "./updateUserDefaultConferencingApp.schema";
|
||||
|
||||
type AppsRouterHandlerCache = {
|
||||
appById?: typeof import("./appById.handler").appByIdHandler;
|
||||
appCredentialsByType?: typeof import("./appCredentialsByType.handler").appCredentialsByTypeHandler;
|
||||
getUsersDefaultConferencingApp?: typeof import("./getUsersDefaultConferencingApp.handler").getUsersDefaultConferencingAppHandler;
|
||||
integrations?: typeof import("./integrations.handler").integrationsHandler;
|
||||
listLocal?: typeof import("./listLocal.handler").listLocalHandler;
|
||||
toggle?: typeof import("./toggle.handler").toggleHandler;
|
||||
saveKeys?: typeof import("./saveKeys.handler").saveKeysHandler;
|
||||
@@ -17,11 +25,67 @@ type AppsRouterHandlerCache = {
|
||||
queryForDependencies?: typeof import("./queryForDependencies.handler").queryForDependenciesHandler;
|
||||
checkGlobalKeys?: typeof import("./checkGlobalKeys.handler").checkForGlobalKeysHandler;
|
||||
setDefaultConferencingApp?: typeof import("./setDefaultConferencingApp.handler").setDefaultConferencingAppHandler;
|
||||
updateUserDefaultConferencingApp?: typeof import("./updateUserDefaultConferencingApp.handler").updateUserDefaultConferencingAppHandler;
|
||||
};
|
||||
|
||||
const UNSTABLE_HANDLER_CACHE: AppsRouterHandlerCache = {};
|
||||
|
||||
export const appsRouter = router({
|
||||
appById: authedProcedure.input(ZAppByIdInputSchema).query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.appById) {
|
||||
UNSTABLE_HANDLER_CACHE.appById = (await import("./appById.handler")).appByIdHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.appById) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.appById({ ctx, input });
|
||||
}),
|
||||
|
||||
appCredentialsByType: authedProcedure
|
||||
.input(ZAppCredentialsByTypeInputSchema)
|
||||
.query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.appCredentialsByType) {
|
||||
UNSTABLE_HANDLER_CACHE.appCredentialsByType = (
|
||||
await import("./appCredentialsByType.handler")
|
||||
).appCredentialsByTypeHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.appCredentialsByType) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.appCredentialsByType({ ctx, input });
|
||||
}),
|
||||
getUsersDefaultConferencingApp: authedProcedure.query(async ({ ctx }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp) {
|
||||
UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp = (
|
||||
await import("./getUsersDefaultConferencingApp.handler")
|
||||
).getUsersDefaultConferencingAppHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.getUsersDefaultConferencingApp({ ctx });
|
||||
}),
|
||||
integrations: authedProcedure.input(ZIntegrationsInputSchema).query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.integrations) {
|
||||
UNSTABLE_HANDLER_CACHE.integrations = (await import("./integrations.handler")).integrationsHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.integrations) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.integrations({ ctx, input });
|
||||
}),
|
||||
listLocal: authedAdminProcedure.input(ZListLocalInputSchema).query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.listLocal) {
|
||||
UNSTABLE_HANDLER_CACHE.listLocal = await import("./listLocal.handler").then(
|
||||
@@ -164,4 +228,20 @@ export const appsRouter = router({
|
||||
input,
|
||||
});
|
||||
}),
|
||||
updateUserDefaultConferencingApp: authedProcedure
|
||||
.input(ZUpdateUserDefaultConferencingAppInputSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp) {
|
||||
UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp = (
|
||||
await import("./updateUserDefaultConferencingApp.handler")
|
||||
).updateUserDefaultConferencingAppHandler;
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.updateUserDefaultConferencingApp({ ctx, input });
|
||||
}),
|
||||
});
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TAppByIdInputSchema } from "./appById.schema";
|
||||
|
||||
type AppByIdOptions = {
|
||||
File renamed without changes.
+1
-1
@@ -1,8 +1,8 @@
|
||||
import { getAllDelegationCredentialsForUserByAppType } from "@calcom/lib/delegationCredential/server";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TAppCredentialsByTypeInputSchema } from "./appCredentialsByType.schema";
|
||||
|
||||
type AppCredentialsByTypeOptions = {
|
||||
File renamed without changes.
+2
-1
@@ -1,5 +1,6 @@
|
||||
import { userMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
|
||||
type GetUsersDefaultConferencingAppOptions = {
|
||||
ctx: {
|
||||
File renamed without changes.
-18
@@ -1,5 +1,3 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { getConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
@@ -13,22 +11,6 @@ type IntegrationsOptions = {
|
||||
input: TIntegrationsInputSchema;
|
||||
};
|
||||
|
||||
export type TeamQuery = Prisma.TeamGetPayload<{
|
||||
select: {
|
||||
id: true;
|
||||
credentials: {
|
||||
select: typeof import("@calcom/prisma/selects/credential").credentialForCalendarServiceSelect;
|
||||
};
|
||||
name: true;
|
||||
logoUrl: true;
|
||||
members: {
|
||||
select: {
|
||||
role: true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}>;
|
||||
|
||||
export const integrationsHandler = async ({ ctx, input }: IntegrationsOptions) => {
|
||||
const user = ctx.user;
|
||||
return getConnectedApps({ user, input, prisma });
|
||||
File renamed without changes.
+1
-1
@@ -4,10 +4,10 @@ import getApps from "@calcom/app-store/utils";
|
||||
import { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { userMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TUpdateUserDefaultConferencingAppInputSchema } from "./updateUserDefaultConferencingApp.schema";
|
||||
|
||||
type UpdateUserDefaultConferencingAppOptions = {
|
||||
Reference in new issue
Block a user