Skip to content

Commit 898afe5

Browse files
committed
WIP: improve IH performance
1 parent d62a045 commit 898afe5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ClusterToName, getFeedsForPublisher } from "../../services/pyth";
44
import { getStatus } from "../../status";
55

66
export const getPriceFeeds = async (cluster: Cluster, key: string) => {
7+
"use cache"
8+
79
const [feeds, rankings] = await Promise.all([
810
getFeedsForPublisher(cluster, key),
911
getRankingsByPublisher(key),

apps/insights/src/services/pyth.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "@pythnetwork/client";
77
import type { PythPriceCallback } from "@pythnetwork/client/lib/PythConnection";
88
import { Connection, PublicKey } from "@solana/web3.js";
9+
import { cache } from "react";
910
import { z } from "zod";
1011

1112
export enum Cluster {
@@ -55,18 +56,22 @@ const clients = {
5556
[Cluster.PythtestConformance]: mkClient(Cluster.PythtestConformance),
5657
} as const;
5758

59+
const getDataForCluster = cache(
60+
(cluster: keyof typeof clients) => clients[cluster].getData()
61+
);
62+
5863
export const getPublishersForFeed = async (
5964
cluster: Cluster,
6065
symbol: string,
6166
) => {
62-
const data = await clients[cluster].getData();
67+
const data = await getDataForCluster(cluster);
6368
return data.productPrice
6469
.get(symbol)
6570
?.priceComponents.map(({ publisher }) => publisher.toBase58());
6671
};
6772

6873
export const getFeeds = async (cluster: Cluster) => {
69-
const data = await clients[cluster].getData();
74+
const data = await getDataForCluster(cluster);
7075
return priceFeedsSchema.parse(
7176
data.symbols.map((symbol) => ({
7277
symbol,
@@ -80,7 +85,7 @@ export const getFeedsForPublisher = async (
8085
cluster: Cluster,
8186
publisher: string,
8287
) => {
83-
const data = await clients[cluster].getData();
88+
const data = await getDataForCluster(cluster);
8489
return priceFeedsSchema.parse(
8590
data.symbols
8691
.filter(

0 commit comments

Comments
 (0)