From 510311a0dc1679a8c59b3cbc14c64ffb2c36e877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20Landstr=C3=B6m?= Date: Tue, 15 Oct 2024 17:01:34 +0200 Subject: [PATCH] fix(SW-194): split CS request of blocks into two --- .../Query/ContentPage/ContentPage.graphql | 10 ++++++- .../routers/contentstack/contentPage/query.ts | 29 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/graphql/Query/ContentPage/ContentPage.graphql b/lib/graphql/Query/ContentPage/ContentPage.graphql index 70cababfd..280eb13ef 100644 --- a/lib/graphql/Query/ContentPage/ContentPage.graphql +++ b/lib/graphql/Query/ContentPage/ContentPage.graphql @@ -37,7 +37,7 @@ query GetContentPage($locale: String!, $uid: String!) { } } -query GetContentPageBlocks($locale: String!, $uid: String!) { +query GetContentPageBlocksBatch1($locale: String!, $uid: String!) { content_page(uid: $uid, locale: $locale) { blocks { __typename @@ -45,6 +45,14 @@ query GetContentPageBlocks($locale: String!, $uid: String!) { ...CardsGrid_ContentPage ...Content_ContentPage ...DynamicContent_ContentPage + } + } +} + +query GetContentPageBlocksBatch2($locale: String!, $uid: String!) { + content_page(uid: $uid, locale: $locale) { + blocks { + __typename ...Shortcuts_ContentPage ...Table_ContentPage ...TextCols_ContentPage diff --git a/server/routers/contentstack/contentPage/query.ts b/server/routers/contentstack/contentPage/query.ts index 18f6e4895..dc7659dc8 100644 --- a/server/routers/contentstack/contentPage/query.ts +++ b/server/routers/contentstack/contentPage/query.ts @@ -1,7 +1,8 @@ import { Lang } from "@/constants/languages" import { GetContentPage, - GetContentPageBlocks, + GetContentPageBlocksBatch1, + GetContentPageBlocksBatch2, } from "@/lib/graphql/Query/ContentPage/ContentPage.graphql" import { request } from "@/lib/graphql/request" import { contentstackExtendedProcedureUID, router } from "@/server/trpc" @@ -18,10 +19,7 @@ import { TrackingChannelEnum, type TrackingSDKPageData, } from "@/types/components/tracking" -import type { - GetContentPageSchema, - GetContentPageSchemaBlocks, -} from "@/types/trpc/routers/contentstack/contentPage" +import type { GetContentPageSchema } from "@/types/trpc/routers/contentstack/contentPage" export const contentPageQueryRouter = router({ get: contentstackExtendedProcedureUID.query(async ({ ctx }) => { @@ -48,7 +46,7 @@ export const contentPageQueryRouter = router({ }) ) - const [mainResponse, blocksResponse] = await Promise.all([ + const [mainResponse, blocksResponse1, blocksResponse2] = await Promise.all([ request( GetContentPage, { locale: lang, uid }, @@ -60,7 +58,17 @@ export const contentPageQueryRouter = router({ } ), request( - GetContentPageBlocks, + GetContentPageBlocksBatch1, + { locale: lang, uid }, + { + cache: "force-cache", + next: { + tags, + }, + } + ), + request( + GetContentPageBlocksBatch2, { locale: lang, uid }, { cache: "force-cache", @@ -75,7 +83,12 @@ export const contentPageQueryRouter = router({ ...mainResponse.data, content_page: { ...mainResponse.data.content_page, - blocks: blocksResponse.data.content_page.blocks, + blocks: [ + blocksResponse1.data.content_page.blocks, + blocksResponse2.data.content_page.blocks, + ] + .flat(2) + .filter((obj) => !(obj && Object.keys(obj).length < 2)), // Remove empty objects and objects with only typename }, }