Template
Remove next/cache usage (use cache, cacheLife, cacheTag, cacheComponents)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F22Ms5Cxam5UHyxaCrtZzu
This commit is contained in:
co-authored by
Claude Fable 5
parent
f23332e42c
commit
1e58ba4ca4
+4
-11
@@ -1,16 +1,14 @@
|
||||
import "server-only";
|
||||
import { analyticsShop as analyticsShopConfig, shop as shopConfig } from "@shared/config";
|
||||
import { cacheLife, cacheTag } from "next/cache";
|
||||
|
||||
import { SHOP_ANALYTICS_QUERY } from "@/lib/queries";
|
||||
import { staticStorefrontClient } from "@/lib/storefront-static";
|
||||
|
||||
/**
|
||||
* Resolve the shop analytics GID best-effort + non-blocking (engineering.md F1).
|
||||
* The query runs inside a `'use cache'` cache-point (`cacheLife("hours")`,
|
||||
* `cacheTag("shop")`) so warm requests resolve instantly. On timeout/error we
|
||||
* fall back to the config-derived shop GID/name (avoids drift — `@shared/config`
|
||||
* `analyticsShop.shopId` is already `gid://shopify/Shop/${shop.shopId}`).
|
||||
* On timeout/error we fall back to the config-derived shop GID/name (avoids
|
||||
* drift — `@shared/config` `analyticsShop.shopId` is already
|
||||
* `gid://shopify/Shop/${shop.shopId}`).
|
||||
*/
|
||||
export type AnalyticsShop = {
|
||||
shopId: string;
|
||||
@@ -24,12 +22,7 @@ const SHOP_FALLBACK: AnalyticsShop = {
|
||||
shopDescription: null,
|
||||
};
|
||||
|
||||
/** Cache the shop query result for hours (it almost never changes). */
|
||||
async function fetchShopAnalytics(): Promise<AnalyticsShop> {
|
||||
"use cache";
|
||||
cacheLife("hours");
|
||||
cacheTag("shop");
|
||||
|
||||
const { data, errors } = await staticStorefrontClient.graphql(SHOP_ANALYTICS_QUERY);
|
||||
if (errors) {
|
||||
console.error("[hydrogen] Root shop query failed", errors);
|
||||
@@ -42,7 +35,7 @@ async function fetchShopAnalytics(): Promise<AnalyticsShop> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Best-effort, non-blocking shop analytics resolution. Races the cached query
|
||||
* Best-effort, non-blocking shop analytics resolution. Races the query
|
||||
* against a 2000ms timeout; on timeout/error falls back to `@shared/config`.
|
||||
* Merges the resolved GID/name with the config-derived `analyticsShop`
|
||||
* metadata (acceptedLanguage/currency/hydrogenSubchannelId).
|
||||
|
||||
Reference in New Issue
Block a user