More memoized requests
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { homeHrefs } from "@/constants/homeHrefs"
|
import { homeHrefs } from "@/constants/homeHrefs"
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { getCurrentHeader } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
@@ -11,9 +11,7 @@ import TopMenu from "../TopMenu"
|
|||||||
import styles from "../header.module.css"
|
import styles from "../header.module.css"
|
||||||
|
|
||||||
export default async function HeaderFallback() {
|
export default async function HeaderFallback() {
|
||||||
const data = await serverClient().contentstack.base.currentHeader({
|
const data = await getCurrentHeader(getLang())
|
||||||
lang: getLang(),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!data?.header) {
|
if (!data?.header) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { homeHrefs } from "@/constants/homeHrefs"
|
import { homeHrefs } from "@/constants/homeHrefs"
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { getLanguageSwitcher, getName } from "@/lib/trpc/memoizedRequests"
|
import {
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
getCurrentHeader,
|
||||||
|
getLanguageSwitcher,
|
||||||
|
getMyPagesNavigation,
|
||||||
|
getName,
|
||||||
|
} from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
@@ -15,12 +19,10 @@ import styles from "./header.module.css"
|
|||||||
|
|
||||||
export default async function Header() {
|
export default async function Header() {
|
||||||
const [data, user, languages, navigation] = await Promise.all([
|
const [data, user, languages, navigation] = await Promise.all([
|
||||||
serverClient().contentstack.base.currentHeader({
|
getCurrentHeader(getLang()),
|
||||||
lang: getLang(),
|
|
||||||
}),
|
|
||||||
getName(),
|
getName(),
|
||||||
getLanguageSwitcher(),
|
getLanguageSwitcher(),
|
||||||
serverClient().contentstack.myPages.navigation.get(),
|
getMyPagesNavigation(),
|
||||||
])
|
])
|
||||||
|
|
||||||
if (!navigation || !languages || !data?.header) {
|
if (!navigation || !languages || !data?.header) {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { MembershipLevelEnum } from "@/constants/membershipLevels"
|
import { MembershipLevelEnum } from "@/constants/membershipLevels"
|
||||||
import { myPages } from "@/constants/routes/myPages"
|
import { myPages } from "@/constants/routes/myPages"
|
||||||
import { getMembershipLevelSafely, getName } from "@/lib/trpc/memoizedRequests"
|
import {
|
||||||
|
getMembershipLevelSafely,
|
||||||
|
getMyPagesNavigation,
|
||||||
|
getName,
|
||||||
|
} from "@/lib/trpc/memoizedRequests"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
@@ -17,7 +21,7 @@ export default async function MyPagesMenuWrapper() {
|
|||||||
const lang = getLang()
|
const lang = getLang()
|
||||||
const [intl, myPagesNavigation, user, membership] = await Promise.all([
|
const [intl, myPagesNavigation, user, membership] = await Promise.all([
|
||||||
getIntl(),
|
getIntl(),
|
||||||
serverClient().contentstack.myPages.navigation.get(),
|
getMyPagesNavigation(),
|
||||||
getName(),
|
getName(),
|
||||||
getMembershipLevelSafely(),
|
getMembershipLevelSafely(),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Fragment } from "react"
|
import { Fragment } from "react"
|
||||||
|
|
||||||
import { logout } from "@/constants/routes/handleAuth"
|
import { logout } from "@/constants/routes/handleAuth"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { getMyPagesNavigation } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import Divider from "@/components/TempDesignSystem/Divider"
|
import Divider from "@/components/TempDesignSystem/Divider"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
@@ -12,7 +12,7 @@ import { getLang } from "@/i18n/serverContext"
|
|||||||
import styles from "./sidebar.module.css"
|
import styles from "./sidebar.module.css"
|
||||||
|
|
||||||
export default async function SidebarMyPages() {
|
export default async function SidebarMyPages() {
|
||||||
const navigation = await serverClient().contentstack.myPages.navigation.get()
|
const navigation = await getMyPagesNavigation()
|
||||||
const { formatMessage } = await getIntl()
|
const { formatMessage } = await getIntl()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ export default async function JoinLoyaltyContact({
|
|||||||
block,
|
block,
|
||||||
}: JoinLoyaltyContactProps) {
|
}: JoinLoyaltyContactProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
const username = await getName()
|
const user = await getName()
|
||||||
|
|
||||||
// Check if we have user, that means we are logged in.
|
// Check if we have user, that means we are logged in.
|
||||||
if (username) {
|
if (user) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { getName } from "@/lib/trpc/memoizedRequests"
|
|||||||
import MyPagesSidebar from "@/components/MyPages/Sidebar"
|
import MyPagesSidebar from "@/components/MyPages/Sidebar"
|
||||||
|
|
||||||
export default async function MyPagesNavigation() {
|
export default async function MyPagesNavigation() {
|
||||||
const username = await getName()
|
const user = await getName()
|
||||||
|
|
||||||
// Check if we have user, that means we are logged in andt the My Pages menu can show.
|
// Check if we have user, that means we are logged in andt the My Pages menu can show.
|
||||||
if (!username) {
|
if (!user) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return <MyPagesSidebar />
|
return <MyPagesSidebar />
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { cache } from "react"
|
import { cache } from "react"
|
||||||
|
|
||||||
|
import { Lang } from "@/constants/languages"
|
||||||
|
|
||||||
import { serverClient } from "../server"
|
import { serverClient } from "../server"
|
||||||
|
|
||||||
export const getLocations = cache(async function getMemoizedLocations() {
|
export const getLocations = cache(async function getMemoizedLocations() {
|
||||||
@@ -10,6 +12,10 @@ export const getProfile = cache(async function getMemoizedProfile() {
|
|||||||
return serverClient().user.get()
|
return serverClient().user.get()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const getName = cache(async function getMemoizedName() {
|
||||||
|
return serverClient().user.name()
|
||||||
|
})
|
||||||
|
|
||||||
export const getProfileSafely = cache(
|
export const getProfileSafely = cache(
|
||||||
async function getMemoizedProfileSafely() {
|
async function getMemoizedProfileSafely() {
|
||||||
return serverClient().user.getSafely()
|
return serverClient().user.getSafely()
|
||||||
@@ -40,10 +46,6 @@ export const getMembershipCards = cache(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const getName = cache(async function getMemoizedName() {
|
|
||||||
return serverClient().user.name()
|
|
||||||
})
|
|
||||||
|
|
||||||
export const getUserTracking = cache(async function getMemoizedUserTracking() {
|
export const getUserTracking = cache(async function getMemoizedUserTracking() {
|
||||||
return serverClient().user.tracking()
|
return serverClient().user.tracking()
|
||||||
})
|
})
|
||||||
@@ -66,6 +68,18 @@ export const getHeader = cache(async function getMemoizedHeader() {
|
|||||||
return serverClient().contentstack.base.header()
|
return serverClient().contentstack.base.header()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const getCurrentHeader = cache(async function getMemoizedCurrentHeader(
|
||||||
|
lang: Lang
|
||||||
|
) {
|
||||||
|
return serverClient().contentstack.base.currentHeader({ lang })
|
||||||
|
})
|
||||||
|
|
||||||
|
export const getMyPagesNavigation = cache(
|
||||||
|
async function getMemoizedMyPagesNavigation() {
|
||||||
|
return serverClient().contentstack.myPages.navigation.get()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export const getLanguageSwitcher = cache(
|
export const getLanguageSwitcher = cache(
|
||||||
async function getMemoizedLanguageSwitcher() {
|
async function getMemoizedLanguageSwitcher() {
|
||||||
return serverClient().contentstack.languageSwitcher.get()
|
return serverClient().contentstack.languageSwitcher.get()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { cache } from "react"
|
||||||
|
|
||||||
import { Lang } from "@/constants/languages"
|
import { Lang } from "@/constants/languages"
|
||||||
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
||||||
import {
|
import {
|
||||||
@@ -92,7 +94,7 @@ import type {
|
|||||||
GetSiteConfigRefData,
|
GetSiteConfigRefData,
|
||||||
} from "@/types/trpc/routers/contentstack/siteConfig"
|
} from "@/types/trpc/routers/contentstack/siteConfig"
|
||||||
|
|
||||||
async function getContactConfig(lang: Lang) {
|
const getContactConfig = cache(async (lang: Lang) => {
|
||||||
getContactConfigCounter.add(1, { lang })
|
getContactConfigCounter.add(1, { lang })
|
||||||
console.info(
|
console.info(
|
||||||
"contentstack.contactConfig start",
|
"contentstack.contactConfig start",
|
||||||
@@ -153,7 +155,7 @@ async function getContactConfig(lang: Lang) {
|
|||||||
JSON.stringify({ query: { lang } })
|
JSON.stringify({ query: { lang } })
|
||||||
)
|
)
|
||||||
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
||||||
}
|
})
|
||||||
|
|
||||||
export const baseQueryRouter = router({
|
export const baseQueryRouter = router({
|
||||||
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user