Scheduling infrastructure for absolutely everyone.
Make i18n a non-batch request and non-cacheable (#3188)
Hariom Balhara09c8f55682ac
diff --git a/apps/web/pages/_app.tsx b/apps/web/pages/_app.tsxindex 430fa399a7e..0c1355c12c5 100644--- a/apps/web/pages/_app.tsx+++ b/apps/web/pages/_app.tsx@@ -81,7 +81,11 @@ export default withTRPC<AppRouter>({}),splitLink({// check for context property `skipBatch`- condition: (op) => op.context.skipBatch === true,+ condition: (op) => {+ // i18n should never be clubbed with other queries, so that it's caching can be managed independently+ // We intend to not cache i18n query+ return op.context.skipBatch === true || op.path === "viewer.public.i18n";+ },// when condition is true, use normal requesttrue: httpLink({ url }),// when condition is false, use batchingdiff --git a/apps/web/pages/api/trpc/[trpc].ts b/apps/web/pages/api/trpc/[trpc].tsindex 11e64840bdc..da0ab1fedaf 100644--- a/apps/web/pages/api/trpc/[trpc].ts+++ b/apps/web/pages/api/trpc/[trpc].ts@@ -37,9 +37,19 @@ export default trpcNext.createNextApiHandler({// checking we're doing a query requestconst isQuery = type === "query";+ // i18n response depends on request header+ const nonCacheableQueries = ["viewer.public.i18n"];+ const isThereANonCacheableQuery = paths?.some((path) => nonCacheableQueries.includes(path));+ const isThereACacheableQuery = paths?.some((path) => !nonCacheableQueries.includes(path));+ if (isThereANonCacheableQuery && isThereACacheableQuery) {+ console.warn(+ "Cacheable and Non-cacheable queries are mixed in the same request. Not going to cache the request"+ );+ }+// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignore ctx.req is available for SSR but not SSG- if (!!ctx?.req && allPublic && allOk && isQuery) {+ if (!!ctx?.req && allPublic && allOk && isQuery && !isThereANonCacheableQuery) {// cache request for 1 day + revalidate once every 5 secondsconst ONE_DAY_IN_SECONDS = 60 * 60 * 24;return {