Skip to content

Commit 7c69871

Browse files
committed
chore: add logs
1 parent 5ca1c24 commit 7c69871

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

apps/insights/src/server/pyth.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,25 @@ export const getPublishersForFeed = async (
77
cluster: Cluster,
88
) => {
99
"use cache";
10+
const start = performance.now();
1011
const data = await clients[cluster].getData();
1112
const result: Record<string, string[]> = {};
1213
for (const key of data.productPrice.keys()) {
1314
const price = data.productPrice.get(key);
1415
result[key] = price?.priceComponents.map(({ publisher }) => publisher.toBase58()) ?? [];
1516
}
17+
const end = performance.now();
18+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
19+
console.log(`getPublishersForFeed: ${end - start}ms`);
1620
return result;
1721
};
1822

1923
const getFeeds = async (cluster: Cluster) => {
2024
"use cache";
25+
const start = performance.now();
2126
const data = await clients[cluster].getData();
2227

23-
return superjson.stringify(priceFeedsSchema.parse(data.symbols.filter(
28+
const result = superjson.stringify(priceFeedsSchema.parse(data.symbols.filter(
2429
(symbol) =>
2530
data.productFromSymbol.get(symbol)?.display_symbol !== undefined,
2631
).map((symbol) => ({
@@ -33,14 +38,22 @@ const getFeeds = async (cluster: Cluster) => {
3338
})) ?? [],
3439
},
3540
}))))
41+
const end = performance.now();
42+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
43+
console.log(`getFeeds: ${end - start}ms`);
44+
return result;
3645
}
3746

3847
export const getFeedsForPublisherCached = async (
3948
cluster: Cluster,
4049
publisher: string,
4150
) => {
51+
const start = performance.now();
4252
const rawFeeds = await getFeeds(cluster);
4353
const feeds = superjson.parse<z.infer<typeof priceFeedsSchema>>(rawFeeds);
54+
const end = performance.now();
55+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
56+
console.log(`getFeedsForPublisherCached: ${end - start}ms`);
4457
return priceFeedsSchema.parse(feeds.filter(({ price }) =>
4558
price.priceComponents.some(
4659
(component) => component.publisher.toString() === publisher,
@@ -50,11 +63,19 @@ export const getFeedsForPublisherCached = async (
5063

5164
export const getFeedsCached = async (cluster: Cluster) => {
5265
"use cache";
66+
const start = performance.now();
5367
const rawFeeds = await getFeeds(cluster);
68+
const end = performance.now();
69+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
70+
console.log(`getFeedsCached: ${end - start}ms`);
5471
return superjson.parse<z.infer<typeof priceFeedsSchema>>(rawFeeds);
5572
};
5673

5774
export const getPublishersForFeedCached = async (cluster: Cluster, symbol: string) => {
75+
const start = performance.now();
5876
const data = await getPublishersForFeed(cluster);
77+
const end = performance.now();
78+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
79+
console.log(`getPublishersForFeedCached: ${end - start}ms`);
5980
return data[symbol];
6081
};

0 commit comments

Comments
 (0)