Skip to content

Commit bc390f6

Browse files
committed
feat(insights): add more cached methods 2
1 parent 6e33dd2 commit bc390f6

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

apps/insights/src/components/Publisher/get-price-feeds.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { getRankingsByPublisher } from "../../services/clickhouse";
2-
import type { Cluster } from "../../services/pyth";
3-
import { ClusterToName, getFeedsForPublisher } from "../../services/pyth";
1+
import { getRankingsByPublisherCached } from '../../server/clickhouse';
2+
import { getFeedsForPublisherCached } from "../../server/pyth";
3+
import { Cluster, ClusterToName } from "../../services/pyth";
44
import { getStatus } from "../../status";
55

66
export const getPriceFeeds = async (cluster: Cluster, key: string) => {
77
const [feeds, rankings] = await Promise.all([
8-
getFeedsForPublisher(cluster, key),
9-
getRankingsByPublisher(key),
8+
getFeedsForPublisherCached(cluster, key),
9+
getRankingsByPublisherCached(key),
1010
]);
1111
return feeds.map((feed) => {
1212
const ranking = rankings.find(

apps/insights/src/components/Publisher/layout.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import type { ReactNode } from "react";
1616
import { Suspense } from "react";
1717

1818
import {
19-
getPublisherRankingHistory,
20-
getPublisherAverageScoreHistory,
21-
getPublishers,
22-
} from "../../services/clickhouse";
19+
getPublishersCached,
20+
getPublisherRankingHistoryCached,
21+
getPublisherAverageScoreHistoryCached,
22+
} from "../../server/clickhouse";
2323
import { getPublisherCaps } from "../../services/hermes";
2424
import { ClusterToName, parseCluster, Cluster } from "../../services/pyth";
2525
import { getPublisherPoolData } from "../../services/staking";
@@ -150,7 +150,7 @@ const RankingCard = async ({
150150
cluster: Cluster;
151151
publisherKey: string;
152152
}) => {
153-
const rankingHistory = await getPublisherRankingHistory(
153+
const rankingHistory = await getPublisherRankingHistoryCached(
154154
cluster,
155155
publisherKey,
156156
);
@@ -234,7 +234,7 @@ const ScoreCard = async ({
234234
cluster: Cluster;
235235
publisherKey: string;
236236
}) => {
237-
const averageScoreHistory = await getPublisherAverageScoreHistory(
237+
const averageScoreHistory = await getPublisherAverageScoreHistoryCached(
238238
cluster,
239239
publisherKey,
240240
);
@@ -338,7 +338,7 @@ const ActiveFeedsCard = async ({
338338
publisherKey: string;
339339
}) => {
340340
const [publishers, priceFeeds] = await Promise.all([
341-
getPublishers(cluster),
341+
getPublishersCached(cluster),
342342
getPriceFeeds(cluster, publisherKey),
343343
]);
344344
const publisher = publishers.find(

apps/insights/src/components/Publisher/performance.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { ReactNode, ComponentProps } from "react";
1515
import { getPriceFeeds } from "./get-price-feeds";
1616
import styles from "./performance.module.scss";
1717
import { TopFeedsTable } from "./top-feeds-table";
18-
import { getPublishers } from "../../services/clickhouse";
18+
import { getPublishersCached } from "../../server/clickhouse";
1919
import type { Cluster } from "../../services/pyth";
2020
import { ClusterToName, parseCluster } from "../../services/pyth";
2121
import { Status } from "../../status";
@@ -48,7 +48,7 @@ export const Performance = async ({ params }: Props) => {
4848
notFound();
4949
}
5050
const [publishers, priceFeeds] = await Promise.all([
51-
getPublishers(parsedCluster),
51+
getPublishersCached(parsedCluster),
5252
getPriceFeeds(parsedCluster, key),
5353
]);
5454
const slicedPublishers = sliceAround(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { lookup as lookupPublisher } from "@pythnetwork/known-publishers";
77

88
import styles from "./index.module.scss";
99
import { PublishersCard } from "./publishers-card";
10-
import { getPublishers } from "../../services/clickhouse";
10+
import { getPublishersCached } from "../../server/clickhouse";
1111
import { getPublisherCaps } from "../../services/hermes";
1212
import { Cluster } from "../../services/pyth";
1313
import {
@@ -27,8 +27,8 @@ const INITIAL_REWARD_POOL_SIZE = 60_000_000_000_000n;
2727
export const Publishers = async () => {
2828
const [pythnetPublishers, pythtestConformancePublishers, oisStats] =
2929
await Promise.all([
30-
getPublishers(Cluster.Pythnet),
31-
getPublishers(Cluster.PythtestConformance),
30+
getPublishersCached(Cluster.Pythnet),
31+
getPublishersCached(Cluster.PythtestConformance),
3232
getOisStats(),
3333
]);
3434

@@ -150,7 +150,7 @@ const toTableRow = ({
150150
permissionedFeeds,
151151
activeFeeds,
152152
averageScore,
153-
}: Awaited<ReturnType<typeof getPublishers>>[number]) => {
153+
}: Awaited<ReturnType<typeof getPublishersCached>>[number]) => {
154154
const knownPublisher = lookupPublisher(key);
155155
return {
156156
id: key,
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11

2-
import { getRankingsBySymbol } from "../services/clickhouse";
2+
import { getPublisherAverageScoreHistory, getPublisherRankingHistory, getPublishers, getRankingsByPublisher, getRankingsBySymbol } from "../services/clickhouse";
3+
import { Cluster } from "../services/pyth";
34

45
export const getRankingsBySymbolCached = async (symbol: string) => {
56
"use cache";
67
return getRankingsBySymbol(symbol);
8+
};
9+
10+
export const getRankingsByPublisherCached = async (publisherKey: string) => {
11+
"use cache";
12+
return getRankingsByPublisher(publisherKey);
13+
};
14+
15+
export const getPublisherAverageScoreHistoryCached = async (cluster: Cluster, key: string) => {
16+
"use cache";
17+
return getPublisherAverageScoreHistory(cluster, key);
18+
};
19+
20+
export const getPublisherRankingHistoryCached = async (cluster: Cluster, key: string) => {
21+
"use cache";
22+
return getPublisherRankingHistory(cluster, key);
23+
};
24+
25+
export const getPublishersCached = async (cluster: Cluster) => {
26+
"use cache";
27+
return getPublishers(cluster);
728
};

apps/insights/src/server/pyth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { Cluster, getFeeds, getPublishersForFeed } from "../services/pyth";
1+
import { Cluster, getFeeds, getFeedsForPublisher, getPublishersForFeed } from "../services/pyth";
22

33
export const getFeedsCached = async (cluster: Cluster) => {
44
"use cache";
55
return getFeeds(cluster);
66
};
77

8+
export const getFeedsForPublisherCached = async (cluster: Cluster, key: string) => {
9+
"use cache";
10+
return getFeedsForPublisher(cluster, key);
11+
};
12+
813
export const getPublishersForFeedCached = async (cluster: Cluster, symbol: string) => {
914
"use cache";
1015
return getPublishersForFeed(cluster, symbol);

0 commit comments

Comments
 (0)