Skip to content

Commit 70ba6f9

Browse files
committed
feat(insights): testing in memory data
1 parent bc390f6 commit 70ba6f9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

apps/insights/src/services/pyth.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export const toCluster = (name: (typeof CLUSTER_NAMES)[number]): Cluster => {
3737
}
3838
};
3939

40+
let inMemoryData: Awaited<ReturnType<typeof clients[Cluster]["getData"]>> | undefined;
41+
42+
const getData = async (cluster: Cluster) => {
43+
inMemoryData ??= await clients[cluster].getData();
44+
return inMemoryData;
45+
};
46+
4047
export const parseCluster = (name: string): Cluster | undefined =>
4148
(CLUSTER_NAMES as readonly string[]).includes(name)
4249
? toCluster(name as (typeof CLUSTER_NAMES)[number])
@@ -65,14 +72,14 @@ export const getPublishersForFeed = async (
6572
cluster: Cluster,
6673
symbol: string,
6774
) => {
68-
const data = await clients[cluster].getData();
75+
const data = await getData(cluster);
6976
return data.productPrice
7077
.get(symbol)
7178
?.priceComponents.map(({ publisher }) => publisher.toBase58());
7279
};
7380

7481
export const getFeeds = async (cluster: Cluster) => {
75-
const data = await clients[cluster].getData();
82+
const data = await getData(cluster);
7683
return priceFeedsSchema.parse(
7784
data.symbols.map((symbol) => ({
7885
symbol,
@@ -86,7 +93,7 @@ export const getFeedsForPublisher = async (
8693
cluster: Cluster,
8794
publisher: string,
8895
) => {
89-
const data = await clients[cluster].getData();
96+
const data = await getData(cluster);
9097
return priceFeedsSchema.parse(
9198
data.symbols
9299
.filter(

0 commit comments

Comments
 (0)