Skip to content

Commit 9b5fce3

Browse files
committed
fix(status): use cacheLife and performance.now()
1 parent 6b4e3fe commit 9b5fce3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

app/login/_components/status/action.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"use server";
22

33
import buildUri from "@/lib/build-uri";
4+
import { unstable_cacheLife as cacheLife } from "next/cache";
45

56
export async function getUpstreamLatency(): Promise<number> {
7+
"use cache";
8+
cacheLife("minutes");
9+
610
try {
7-
const start = Date.now();
11+
const start = performance.now();
812

9-
const response = await fetch(buildUri("/"), {
10-
next: {
11-
revalidate: 120, // update latency every 2 minutes
12-
},
13-
});
13+
const response = await fetch(buildUri("/"));
1414
if (!response.ok) {
1515
return -1;
1616
}
1717

18-
return Date.now() - start;
18+
return Math.round(performance.now() - start);
1919
} catch (error) {
2020
console.error("Error getting upstream status:", error);
2121
return -1;

0 commit comments

Comments
 (0)