Merged in fix/cache-graphql-data (pull request #2248)

fix: add missing cache for cms data

* fix: cache cms data


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-05-28 08:28:21 +00:00
committed by Linus Flood
parent 1d733c5ca3
commit 26b005d72a
4 changed files with 24 additions and 11 deletions

View File

@@ -25,6 +25,10 @@ export default async function CurrentContentPage({
{ {
locale: params.lang, locale: params.lang,
url: searchParams.uri, url: searchParams.uri,
},
{
key: `${params.lang}:current-block-page:${searchParams.uri}`,
ttl: "max",
} }
) )
@@ -38,7 +42,11 @@ export default async function CurrentContentPage({
// This is currently to be considered a temporary solution to provide the tracking with a few values in english to align with existing reports // This is currently to be considered a temporary solution to provide the tracking with a few values in english to align with existing reports
const pageDataForTracking = await request<TrackingData>( const pageDataForTracking = await request<TrackingData>(
GetCurrentBlockPageTrackingData, GetCurrentBlockPageTrackingData,
{ uid: response.data.all_current_blocks_page.items[0].system.uid } { uid: response.data.all_current_blocks_page.items[0].system.uid },
{
key: `${params.lang}:current-block-page-tracking:${searchParams.uri}`,
ttl: "max",
}
) )
const pageData = response.data.all_current_blocks_page.items[0] const pageData = response.data.all_current_blocks_page.items[0]

View File

@@ -12,6 +12,8 @@ services:
- PRIMARY_API_KEY= - PRIMARY_API_KEY=
- SECONDARY_API_KEY= - SECONDARY_API_KEY=
- NODE_ENV=development - NODE_ENV=development
- SENTRY_DSN=fake-dsn
- SENTRY_ENVIRONMENT=development
redis: redis:
image: redis:6 image: redis:6
ports: ports:

View File

@@ -81,6 +81,9 @@ export async function request<T>(
const response = await client.request<T>({ const response = await client.request<T>({
document: query, document: query,
variables, variables,
requestHeaders: {
"User-Agent": `scandic-web-${env.SENTRY_ENVIRONMENT}`,
},
}) })
try { try {

View File

@@ -3,7 +3,6 @@ import { request } from "@/lib/graphql/request"
import { notFound } from "@/server/errors/trpc" import { notFound } from "@/server/errors/trpc"
import { createCounter } from "@/server/telemetry" import { createCounter } from "@/server/telemetry"
import { getCacheClient } from "@/services/dataCache"
import { import {
generateRefsResponseTag, generateRefsResponseTag,
generateTag, generateTag,
@@ -32,16 +31,17 @@ export async function fetchCollectionPageRefs(lang: Lang, uid: string) {
metricsGetCollectionPageRefs.start() metricsGetCollectionPageRefs.start()
const cacheClient = await getCacheClient()
const cacheKey = generateRefsResponseTag(lang, uid) const cacheKey = generateRefsResponseTag(lang, uid)
const refsResponse = await cacheClient.cacheOrGet( const refsResponse = await request<GetCollectionPageRefsSchema>(
cacheKey, GetCollectionPageRefs,
async () => {
await request<GetCollectionPageRefsSchema>(GetCollectionPageRefs, { locale: lang,
locale: lang, uid,
uid, },
}), {
"max" key: cacheKey,
ttl: "max",
}
) )
if (!refsResponse.data) { if (!refsResponse.data) {