Skip to content

Commit b9c588b

Browse files
committed
chore: time functions
1 parent 1872162 commit b9c588b

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

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

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

5-
import { getFeedsCached } from "../../../server/pyth/get-feeds";
5+
import { getFeedsCached } from "../../../server/pyth";
66
import { Cluster } from "../../../services/pyth";
77

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "../../config/server";
1212
import { LivePriceDataProvider } from "../../hooks/use-live-price-data";
1313
import { getPublishersCached } from '../../server/clickhouse';
14-
import { getFeedsCached } from '../../server/pyth/get-feeds';
14+
import { getFeedsCached } from '../../server/pyth';
1515
import { Cluster } from "../../services/pyth";
1616
import { PriceFeedIcon } from "../PriceFeedIcon";
1717
import { PublisherIcon } from "../PublisherIcon";

apps/insights/src/config/server.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Disable the following rule because this file is the intended place to declare
22
// and load all env variables.
3-
/* eslint-disable n/no-process-env, @typescript-eslint/no-non-null-assertion, turbo/no-undeclared-env-vars */
3+
/* eslint-disable n/no-process-env */
44

55
import { Redis } from 'ioredis';
66
import "server-only";
@@ -63,10 +63,7 @@ export const ENABLE_ACCESSIBILITY_REPORTING =
6363
let redisClient: Redis | undefined;
6464

6565
export function getRedis(): Redis {
66-
const url = process.env.REDIS_URL;
67-
if (!url) {
68-
throw new Error('REDIS_URL must be set');
69-
}
66+
const url = demand("REDIS_URL");
7067
if(redisClient) {
7168
return redisClient;
7269
}
@@ -76,13 +73,14 @@ export function getRedis(): Redis {
7673

7774
export const PUBLIC_URL = (() => {
7875
if (IS_PRODUCTION_SERVER) {
79-
80-
return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL!}`;
76+
const productionUrl = demand("VERCEL_PROJECT_PRODUCTION_URL");
77+
return `https://${productionUrl}`;
8178
} else if (IS_PREVIEW_SERVER) {
82-
return `https://${process.env.VERCEL_URL!}`;
79+
const previewUrl = demand("VERCEL_URL");
80+
return `https://${previewUrl}`;
8381
} else {
8482
return `http://localhost:3003`;
8583
}
8684
})();
8785

88-
export const VERCEL_AUTOMATION_BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET!;
86+
export const VERCEL_AUTOMATION_BYPASS_SECRET = demand("VERCEL_AUTOMATION_BYPASS_SECRET");

apps/insights/src/server/pyth.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export async function getFeedsForPublisherCached(
3838
}
3939

4040
export const getFeedsCached = async (cluster: Cluster) => {
41+
const start = Date.now();
4142
const data = await fetch(`${PUBLIC_URL}/api/pyth/get-feeds?cluster=${cluster.toString()}&excludePriceComponents=true`, {
4243
next: {
4344
revalidate: DEFAULT_CACHE_TTL,
@@ -48,10 +49,14 @@ export const getFeedsCached = async (cluster: Cluster) => {
4849
});
4950
const dataJson = await data.text();
5051
const feeds: Omit<z.infer<typeof priceFeedsSchema>[0], "price">[] = parse(dataJson);
52+
const end = Date.now();
53+
// eslint-disable-next-line no-console
54+
console.log("getFeedsCached", cluster, end - start);
5155
return feeds;
5256
}
5357

5458
export const getFeedForSymbolCached = async ({symbol, cluster = Cluster.Pythnet}: {symbol: string, cluster?: Cluster}): Promise<z.infer<typeof priceFeedsSchema>[0] | undefined> => {
59+
const start = Date.now();
5560
const data = await fetch(`${PUBLIC_URL}/api/pyth/get-feeds/${encodeURIComponent(symbol)}?cluster=${cluster.toString()}`, {
5661
next: {
5762
revalidate: DEFAULT_CACHE_TTL,
@@ -60,12 +65,15 @@ export const getFeedForSymbolCached = async ({symbol, cluster = Cluster.Pythnet}
6065
'x-vercel-protection-bypass': VERCEL_AUTOMATION_BYPASS_SECRET,
6166
},
6267
});
63-
68+
6469
if(!data.ok) {
6570
return undefined;
6671
}
6772

6873
const dataJson = await data.text();
6974
const feed: z.infer<typeof priceFeedsSchema>[0] = parse(dataJson);
75+
const end = Date.now();
76+
// eslint-disable-next-line no-console
77+
console.log("getFeedForSymbolCached", symbol, cluster, end - start);
7078
return feed;
7179
}

apps/insights/turbo.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"DISABLE_ACCESSIBILITY_REPORTING",
1717
"NEXT_PUBLIC_PYTHNET_RPC",
1818
"NEXT_PUBLIC_PYTHTEST_CONFORMANCE_RPC",
19-
"REDIS_URL"
19+
"REDIS_URL",
20+
"VERCEL_PROJECT_PRODUCTION_URL"
2021
]
2122
},
2223
"fix:lint": {

0 commit comments

Comments
 (0)