Skip to content

Commit 2e2f8bb

Browse files
Alexandru CamboseAlexandru Cambose
authored andcommitted
feat: add cached methods
1 parent b9ad8f2 commit 2e2f8bb

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

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

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

5-
import { Cluster, getFeeds } from "../../../services/pyth";
5+
import { getFeedsCached } from "../../../server/pyth";
6+
import { Cluster } from "../../../services/pyth";
67

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

@@ -19,7 +20,7 @@ export const generateMetadata = async ({
1920
}: Props): Promise<Metadata> => {
2021
const [{ slug }, feeds] = await Promise.all([
2122
params,
22-
getFeeds(Cluster.Pythnet),
23+
getFeedsCached(Cluster.Pythnet),
2324
]);
2425
const symbol = decodeURIComponent(slug);
2526
const feed = feeds.find((item) => item.symbol === symbol);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ 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 { Cluster, getFeeds } from "../../services/pyth";
12+
import { getFeedsCached } from "../../server/pyth";
13+
import { Cluster } from "../../services/pyth";
1314
import {
1415
totalVolumeTraded,
1516
activeChains,
@@ -23,7 +24,7 @@ import { FormattedDate } from "../FormattedDate";
2324
import { FormattedNumber } from "../FormattedNumber";
2425

2526
export const Overview = async () => {
26-
const priceFeeds = await getFeeds(Cluster.Pythnet);
27+
const priceFeeds = await getFeedsCached(Cluster.Pythnet);
2728
const today = new Date();
2829
const feedCounts = [
2930
...activeFeeds.map(({ date, numFeeds }) => ({
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { notFound } from "next/navigation";
22

3-
import { Cluster, getFeeds } from "../../services/pyth";
3+
import { getFeedsCached } from "../../server/pyth";
4+
import { Cluster } from "../../services/pyth";
45

56
export const getFeed = async (params: Promise<{ slug: string }>) => {
67
"use cache";
78

8-
const [{ slug }, feeds] = await Promise.all([params, getPythnetFeeds()]);
9+
const [{ slug }, feeds] = await Promise.all([params, getFeedsCached(Cluster.Pythnet)]);
910
const symbol = decodeURIComponent(slug);
1011
return {
1112
feeds,
1213
feed: feeds.find((item) => item.symbol === symbol) ?? notFound(),
1314
symbol,
1415
} as const;
1516
};
16-
17-
const getPythnetFeeds = async () => {
18-
"use cache";
19-
return getFeeds(Cluster.Pythnet);
20-
};

apps/insights/src/components/PriceFeed/publishers.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { lookup as lookupPublisher } from "@pythnetwork/known-publishers";
22
import { notFound } from "next/navigation";
33

4+
import { PublishersCard } from "./publishers-card";
5+
import { getFeedsCached, getPublishersForFeedCached } from "../../server/pyth";
46
import { getRankingsBySymbol } from "../../services/clickhouse";
57
import {
68
Cluster,
79
ClusterToName,
8-
getFeeds,
9-
getPublishersForFeed,
1010
} from "../../services/pyth";
1111
import { getStatus } from "../../status";
1212
import { PublisherIcon } from "../PublisherIcon";
1313
import { PublisherTag } from "../PublisherTag";
14-
import { PublishersCard } from "./publishers-card";
1514

1615
type Props = {
1716
params: Promise<{
@@ -28,8 +27,8 @@ export const Publishers = async ({ params }: Props) => {
2827
pythnetPublishers,
2928
pythtestConformancePublishers,
3029
] = await Promise.all([
31-
getFeeds(Cluster.Pythnet),
32-
getFeeds(Cluster.PythtestConformance),
30+
getFeedsCached(Cluster.Pythnet),
31+
getFeedsCached(Cluster.PythtestConformance),
3332
getPublishers(Cluster.Pythnet, symbol),
3433
getPublishers(Cluster.PythtestConformance, symbol),
3534
]);
@@ -87,7 +86,7 @@ export const PublishersLoading = () => <PublishersCard isLoading />;
8786

8887
const getPublishers = async (cluster: Cluster, symbol: string) => {
8988
const [publishers, rankings] = await Promise.all([
90-
getPublishersForFeed(cluster, symbol),
89+
getPublishersForFeedCached(cluster, symbol),
9190
getRankingsBySymbol(symbol),
9291
]);
9392

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { AssetClassTable } from "./asset-class-table";
1919
import { ComingSoonList } from "./coming-soon-list";
2020
import styles from "./index.module.scss";
2121
import { PriceFeedsCard } from "./price-feeds-card";
22-
import { Cluster, getFeeds } from "../../services/pyth";
22+
import { getFeedsCached } from "../../server/pyth";
23+
import { Cluster } from "../../services/pyth";
2324
import { priceFeeds as priceFeedsStaticConfig } from "../../static-data/price-feeds";
2425
import { activeChains } from "../../static-data/stats";
2526
import { Cards } from "../Cards";
@@ -289,7 +290,7 @@ const FeaturedFeedsCard = <T extends ElementType>({
289290
);
290291

291292
const getPriceFeeds = async () => {
292-
const priceFeeds = await getFeeds(Cluster.Pythnet);
293+
const priceFeeds = await getFeedsCached(Cluster.Pythnet);
293294
const activeFeeds = priceFeeds.filter((feed) => isActive(feed));
294295
const comingSoon = priceFeeds.filter((feed) => !isActive(feed));
295296
return { activeFeeds, comingSoon };

apps/insights/src/server/pyth.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Cluster, getFeeds, getPublishersForFeed } from "../services/pyth";
2+
3+
export const getFeedsCached = async (cluster: Cluster) => {
4+
"use cache";
5+
return getFeeds(cluster);
6+
};
7+
8+
export const getPublishersForFeedCached = async (cluster: Cluster, symbol: string) => {
9+
"use cache";
10+
return getPublishersForFeed(cluster, symbol);
11+
};

0 commit comments

Comments
 (0)