Skip to content

Commit 63bc74b

Browse files
committed
fix(dashboard): memoize rpc chart
1 parent 05c6390 commit 63bc74b

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

apps/dashboard/src/app/team/[team_slug]/[project_slug]/components/RpcMethodBarChartCard/RpcMethodBarChartCardUI.tsx

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,50 @@ export function RpcMethodBarChartCardUI({
3030
[rawData],
3131
);
3232

33-
const data = useMemo(
34-
() =>
35-
uniqueDates.map((date) => {
36-
const dateData: { [key: string]: string | number } = { date };
37-
for (const method of uniqueMethods) {
38-
const methodData = rawData.find(
39-
(d) => d.date === date && d.evmMethod === method,
40-
);
41-
dateData[method] = methodData?.count ?? 0;
42-
}
33+
const data = useMemo(() => {
34+
return uniqueDates.map((date) => {
35+
const dateData: { [key: string]: string | number } = { date };
36+
for (const method of uniqueMethods) {
37+
const methodData = rawData.find(
38+
(d) => d.date === date && d.evmMethod === method,
39+
);
40+
dateData[method] = methodData?.count ?? 0;
41+
}
4342

44-
// If we have too many methods to display well, add "other" and group the lowest keys for each time period
45-
if (uniqueMethods.length > 5) {
46-
// If we haven't added "other" as a key yet, add it
47-
if (!uniqueMethods.includes("Other")) {
48-
uniqueMethods.push("Other");
49-
}
43+
// If we have too many methods to display well, add "other" and group the lowest keys for each time period
44+
if (uniqueMethods.length > 5) {
45+
// If we haven't added "other" as a key yet, add it
46+
if (!uniqueMethods.includes("Other")) {
47+
uniqueMethods.push("Other");
48+
}
5049

51-
// Sort the methods by their count for the time period
52-
const sortedMethods = uniqueMethods
53-
.filter((m) => m !== "Other")
54-
.sort(
55-
(a, b) =>
56-
((dateData[b] as number) ?? 0) - ((dateData[a] as number) ?? 0),
57-
);
50+
// Sort the methods by their count for the time period
51+
const sortedMethods = uniqueMethods
52+
.filter((m) => m !== "Other")
53+
.sort(
54+
(a, b) =>
55+
((dateData[b] as number) ?? 0) - ((dateData[a] as number) ?? 0),
56+
);
5857

59-
dateData.Other = 0;
60-
for (const method of sortedMethods.slice(5, sortedMethods.length)) {
61-
dateData.Other += (dateData[method] as number) ?? 0;
62-
delete dateData[method];
63-
}
58+
dateData.Other = 0;
59+
for (const method of sortedMethods.slice(5, sortedMethods.length)) {
60+
dateData.Other += (dateData[method] as number) ?? 0;
61+
delete dateData[method];
6462
}
65-
return dateData;
66-
}),
67-
[uniqueDates, uniqueMethods, rawData],
68-
);
63+
}
64+
return dateData;
65+
});
66+
}, [uniqueDates, uniqueMethods, rawData]);
6967

70-
const config: ChartConfig = {};
71-
for (const method of uniqueMethods) {
72-
config[method] = {
73-
label: method,
74-
};
75-
}
68+
const config: ChartConfig = useMemo(() => {
69+
const config: ChartConfig = {};
70+
for (const method of uniqueMethods) {
71+
config[method] = {
72+
label: method,
73+
};
74+
}
75+
return config;
76+
}, [uniqueMethods]);
7677

7778
if (
7879
data.length === 0 ||

0 commit comments

Comments
 (0)