-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: split up routers to separate lambdas #8041
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
25fafc0
split up routers to separate lambdas
juliusmarminge 6b719a2
fix responsemeta
juliusmarminge 4ec8c9a
move
juliusmarminge 70a34f7
add typeguards to make sure all endpoints are covered in the approuter
juliusmarminge 0a993e5
prettier
juliusmarminge ed78cb2
move slotsrouter
juliusmarminge 0dddf3c
split ssg/ssr
juliusmarminge 6a4df55
make sure correct headers are sent on viewer.public
juliusmarminge 13ed9f4
make sure correct headers are sent + use ctx.prisma
juliusmarminge b02b169
Merge branch 'main' into split-router
roae ae25067
Merge branch 'main' into split-router
emrysal fee7d26
Merged with main
emrysal 176f5c8
Merge branch 'main' into split-router
emrysal 775973c
Fixed new prefetch broken by merge
emrysal 042729c
Merge branch 'main' into split-router
PeerRich c9b6a6d
Merge branch 'main' into split-router
keithwillcode 201f978
Merge branch 'main' into pr/8041
zomars af5c7c5
Merge branch 'main' into pr/8041
zomars b12329d
Merge remote-tracking branch 'calcom/main' into split-router
keithwillcode 3177ca4
Fixes after merge
keithwillcode 7e2c348
Created separate API route for all tRPC routers
keithwillcode 5188527
More fixes from refactor
keithwillcode 970f6f1
Fixed tRPC query for slots
keithwillcode 21db6cc
Put back extra line
keithwillcode 2232d26
Fixed type checks
keithwillcode 112f5fb
Removed Endpoint type check since it loads from client
keithwillcode d298846
Reverted change in getSchedule test
keithwillcode 8befee5
Merge branch 'main' into split-router
keithwillcode eb3858e
Merge branch 'main' into split-router
keithwillcode 656ce94
Merge branch 'main' into split-router
keithwillcode 2d39cd9
Merge branch 'main' into split-router
keithwillcode d7fa176
Merge branch 'main' into split-router
keithwillcode e7b6109
Fix trpc routes in expectations
hariombalhara f8fcc12
Fix one more route test
hariombalhara 4d1e31d
Merge branch 'main' into split-router
keithwillcode 0fbba6f
Merge branch 'main' into split-router
keithwillcode 86a3a7e
Merge branch 'main' into split-router
keithwillcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { apiKeysRouter } from "@calcom/trpc/server/routers/viewer/apiKeys/_router"; | ||
|
||
export default createNextApiHandler(apiKeysRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import appRoutingForms from "@calcom/app-store/routing-forms/trpc-router"; | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
|
||
export default createNextApiHandler(appRoutingForms); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { appsRouter } from "@calcom/trpc/server/routers/viewer/apps/_router"; | ||
|
||
export default createNextApiHandler(appsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { authRouter } from "@calcom/trpc/server/routers/viewer/auth/_router"; | ||
|
||
export default createNextApiHandler(authRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { availabilityRouter } from "@calcom/trpc/server/routers/viewer/availability/_router"; | ||
|
||
export default createNextApiHandler(availabilityRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { bookingsRouter } from "@calcom/trpc/server/routers/viewer/bookings/_router"; | ||
|
||
export default createNextApiHandler(bookingsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { deploymentSetupRouter } from "@calcom/trpc/server/routers/viewer/deploymentSetup/_router"; | ||
|
||
export default createNextApiHandler(deploymentSetupRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import ethRouter from "@calcom/app-store/rainbow/trpc/router"; | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
|
||
export default createNextApiHandler(ethRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { eventTypesRouter } from "@calcom/trpc/server/routers/viewer/eventTypes/_router"; | ||
|
||
export default createNextApiHandler(eventTypesRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { featureFlagRouter } from "@calcom/features/flags/server/router"; | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
|
||
export default createNextApiHandler(featureFlagRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { insightsRouter } from "@calcom/features/insights/server/trpc-router"; | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
|
||
export default createNextApiHandler(insightsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { paymentsRouter } from "@calcom/trpc/server/routers/viewer/payments/_router"; | ||
|
||
export default createNextApiHandler(paymentsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router"; | ||
|
||
export default createNextApiHandler(publicViewerRouter, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { ssoRouter } from "@calcom/trpc/server/routers/viewer/sso/_router"; | ||
|
||
export default createNextApiHandler(ssoRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { slotsRouter } from "@calcom/trpc/server/routers/viewer/slots/_router"; | ||
|
||
export default createNextApiHandler(slotsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { viewerTeamsRouter } from "@calcom/trpc/server/routers/viewer/teams/_router"; | ||
|
||
export default createNextApiHandler(viewerTeamsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { userAdminRouter } from "@calcom/features/ee/users/server/trpc-router"; | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
|
||
export default createNextApiHandler(userAdminRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { loggedInViewerRouter } from "@calcom/trpc/server/routers/loggedInViewer/_router"; | ||
|
||
export default createNextApiHandler(loggedInViewerRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { webhookRouter } from "@calcom/trpc/server/routers/viewer/webhook/_router"; | ||
|
||
export default createNextApiHandler(webhookRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
import { workflowsRouter } from "@calcom/trpc/server/routers/viewer/workflows/_router"; | ||
|
||
export default createNextApiHandler(workflowsRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { z } from "zod"; | ||
import type { AnyRouter } from "@trpc/server"; | ||
import * as trpcNext from "@calcom/trpc/server/adapters/next"; | ||
import { createContext as createTrpcContext } from "@calcom/trpc/server/createContext"; | ||
|
||
/** | ||
* Creates an API handler executed by Next.js. | ||
*/ | ||
export function createNextApiHandler(router: AnyRouter, isPublic: boolean = false) { | ||
return trpcNext.createNextApiHandler({ | ||
router, | ||
/** | ||
* @link https://trpc.io/docs/context | ||
*/ | ||
createContext: ({ req, res }) => { | ||
return createTrpcContext({ req, res }); | ||
}, | ||
/** | ||
* @link https://trpc.io/docs/error-handling | ||
*/ | ||
onError({ error }) { | ||
if (error.code === "INTERNAL_SERVER_ERROR") { | ||
// send to bug reporting | ||
console.error("Something went wrong", error); | ||
} | ||
}, | ||
/** | ||
* Enable query batching | ||
*/ | ||
batching: { | ||
enabled: true, | ||
}, | ||
/** | ||
* @link https://trpc.io/docs/caching#api-response-caching | ||
*/ | ||
responseMeta({ ctx, paths, type, errors }) { | ||
const allOk = errors.length === 0; | ||
const isQuery = type === "query"; | ||
const noHeaders = {}; | ||
|
||
// We cannot set headers on SSG queries | ||
if (!ctx?.res) return noHeaders; | ||
|
||
const defaultHeaders: Record<"headers", Record<string, string>> = { | ||
headers: {}, | ||
}; | ||
|
||
const timezone = z.string().safeParse(ctx.req?.headers["x-vercel-ip-timezone"]); | ||
if (timezone.success) defaultHeaders.headers["x-cal-timezone"] = timezone.data; | ||
|
||
// We need all these conditions to be true to set cache headers | ||
if (!(isPublic && allOk && isQuery)) return defaultHeaders; | ||
|
||
// No cache by default | ||
defaultHeaders.headers["cache-control"] = `no-cache`; | ||
|
||
if (isPublic && paths) { | ||
const ONE_DAY_IN_SECONDS = 60 * 60 * 24; | ||
const cacheRules = { | ||
"session": `no-cache`, | ||
"i18n": `no-cache`, | ||
// Revalidation time here should be 1 second, per https://github.com/calcom/cal.com/pull/6823#issuecomment-1423215321 | ||
"slots.getSchedule": `no-cache`, // FIXME | ||
"cityTimezones": `max-age=${ONE_DAY_IN_SECONDS}, stale-while-revalidate`, | ||
} as const; | ||
|
||
const matchedPath = paths.find((v) => v in cacheRules) as keyof typeof cacheRules; | ||
if (matchedPath) defaultHeaders.headers["cache-control"] = cacheRules[matchedPath]; | ||
} | ||
|
||
return defaultHeaders; | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make sure this is deployed on different lambdas maybe we should have a slightly different configuration on each path as discussed in slack.
Here an example, this changes must be added to the vercel.json
cc @emrysal
b803c61