Skip to content

Commit 0ffdaee

Browse files
committed
chore: test with unstable_cache
1 parent e862ca4 commit 0ffdaee

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

apps/insights/src/app/api/pyth/get-feeds/[symbol]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NextResponse } from "next/server";
22
import { stringify } from 'superjson';
33

4-
import { getFeedsCached } from "../../../../../server/pyth/get-feeds";
4+
import { getFeedsCached } from "../../../../../server/pyth";
55
import { Cluster } from "../../../../../services/pyth";
66

77
export const GET = async (request: Request, { params }: { params: Promise<{ symbol: string }> }) => {

apps/insights/src/app/price-feeds/[slug]/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Metadata } from "next";
22
import { notFound } from "next/navigation";
33
import type { ReactNode } from "react";
44

5-
import { getFeedsCached } from "../../../server/pyth/get-feeds";
5+
import { getFeedsCached } from "../../../server/pyth";
66
import { Cluster } from "../../../services/pyth";
77

88
export { PriceFeedLayout as default } from "../../../components/PriceFeed/layout";

apps/insights/src/components/Overview/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import PriceFeedsLight from "./price-feeds-light.svg";
99
import PublishersDark from "./publishers-dark.svg";
1010
import PublishersLight from "./publishers-light.svg";
1111
import { TabList } from "./tab-list";
12-
import { getFeedsCached } from "../../server/pyth/get-feeds";
12+
import { getFeedsCached } from "../../server/pyth";
1313
import { Cluster } from "../../services/pyth";
1414
import {
1515
totalVolumeTraded,

apps/insights/src/components/Root/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "../../config/server";
1212
import { LivePriceDataProvider } from "../../hooks/use-live-price-data";
1313
import { getPublishersCached } from '../../server/clickhouse';
14-
import { getFeedsCached } from '../../server/pyth/get-feeds';
14+
import { getFeedsCached } from '../../server/pyth';
1515
import { Cluster } from "../../services/pyth";
1616
import { PriceFeedIcon } from "../PriceFeedIcon";
1717
import { PublisherIcon } from "../PublisherIcon";

apps/insights/src/server/pyth.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { unstable_cache } from "next/cache";
12
import { parse, } from "superjson";
23
import { z } from "zod";
34

45
import { PUBLIC_URL, VERCEL_AUTOMATION_BYPASS_SECRET } from '../config/server';
56
import { Cluster, priceFeedsSchema } from "../services/pyth";
67
import { DEFAULT_CACHE_TTL } from "../utils/cache";
8+
import { getFeedsCached as _getFeedsCached } from "./pyth/get-feeds";
79

810
export async function getPublishersForFeedCached(
911
cluster: Cluster,
@@ -36,19 +38,39 @@ export async function getFeedsForPublisherCached(
3638
return parse<z.infer<typeof priceFeedsSchema>>(rawData);
3739
}
3840

41+
const _privateGetFeeds =unstable_cache(async (cluster: Cluster) => {
42+
const start = Date.now();
43+
const feeds = await _getFeedsCached(cluster) as Omit<z.infer<typeof priceFeedsSchema>[number], 'price'>[];
44+
const end = Date.now();
45+
// eslint-disable-next-line no-console
46+
console.log("internal getFeedsCached", cluster, end - start);
47+
return feeds.map((feed) => ({
48+
...feed,
49+
price: undefined,
50+
}));
51+
// const data = await fetch(`${PUBLIC_URL}/api/pyth/get-feeds?cluster=${cluster.toString()}&excludePriceComponents=true`, {
52+
// next: {
53+
// revalidate: DEFAULT_CACHE_TTL,
54+
// },
55+
// headers: {
56+
// 'x-vercel-protection-bypass': VERCEL_AUTOMATION_BYPASS_SECRET,
57+
// },
58+
// });
59+
// const dataJson = await data.text();
60+
// const feeds: Omit<z.infer<typeof priceFeedsSchema>[0], "price">[] = parse(dataJson);
61+
// return feeds;
62+
}, [], {
63+
revalidate: DEFAULT_CACHE_TTL,
64+
});
65+
3966
export const getFeedsCached = async (cluster: Cluster) => {
40-
const data = await fetch(`${PUBLIC_URL}/api/pyth/get-feeds?cluster=${cluster.toString()}&excludePriceComponents=true`, {
41-
next: {
42-
revalidate: DEFAULT_CACHE_TTL,
43-
},
44-
headers: {
45-
'x-vercel-protection-bypass': VERCEL_AUTOMATION_BYPASS_SECRET,
46-
},
47-
});
48-
const dataJson = await data.text();
49-
const feeds: Omit<z.infer<typeof priceFeedsSchema>[0], "price">[] = parse(dataJson);
50-
return feeds;
51-
}
67+
const start = Date.now();
68+
const data = await _privateGetFeeds(cluster);
69+
const end = Date.now();
70+
// eslint-disable-next-line no-console
71+
console.log("getFeedsCached", end - start);
72+
return data;
73+
};
5274

5375
export const getFeedForSymbolCached = async ({symbol, cluster = Cluster.Pythnet}: {symbol: string, cluster?: Cluster}): Promise<z.infer<typeof priceFeedsSchema>[0] | undefined> => {
5476
const data = await fetch(`${PUBLIC_URL}/api/pyth/get-feeds/${encodeURIComponent(symbol)}?cluster=${cluster.toString()}`, {

0 commit comments

Comments
 (0)