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