Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue #758

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions packages/web/src/components/VaultCard/OptedInList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { HackerProfileImage } from "components/HackerProfile";
import { WithTooltip } from "components/WithTooltip/WithTooltip";
import { useAuditFrameGame } from "hooks/auditFrameGame";
import { RoutePaths } from "navigation";
import { useAllProfiles, useCachedProfile } from "pages/HackerProfile/useCachedProfile";
import { useAllTimeLeaderboard } from "pages/Leaderboard/LeaderboardPage/components/AllTimeLeaderboard/useAllTimeLeaderboard";
import { useCachedProfile } from "pages/HackerProfile/useCachedProfile";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { StyledOptedInList } from "./styles";
Expand All @@ -20,21 +19,22 @@ export const OptedInList = ({ editSessionIdOrAddress }: IOptedInListProps) => {
const {
optedInList: { data },
} = useAuditFrameGame(editSessionIdOrAddress);
const { data: profiles } = useAllProfiles();
const { leaderboard } = useAllTimeLeaderboard();
const leaderboardWithUsernames = leaderboard?.map((entry) => {
const profile = profiles?.find((profile) => profile.addresses.includes(entry.address.toLowerCase()));
return {
...entry,
username: profile?.username,
};
});
// TODO: Cache the leaderboard in order to avoid performance issues
// const { data: profiles } = useAllProfiles();
// const { leaderboard } = useAllTimeLeaderboard();
// const leaderboardWithUsernames = leaderboard?.map((entry) => {
// const profile = profiles?.find((profile) => profile.addresses.includes(entry.address.toLowerCase()));
// return {
// ...entry,
// username: profile?.username,
// };
// });

(data as string[])?.sort((a, b) => {
const aIndex = leaderboardWithUsernames?.findIndex((entry) => entry.username?.toLowerCase() === a.toLowerCase());
const bIndex = leaderboardWithUsernames?.findIndex((entry) => entry.username?.toLowerCase() === b.toLowerCase());
return (aIndex === -1 ? 10000000 : aIndex) - (bIndex === -1 ? 10000000 : bIndex);
});
// (data as string[])?.sort((a, b) => {
// const aIndex = leaderboardWithUsernames?.findIndex((entry) => entry.username?.toLowerCase() === a.toLowerCase());
// const bIndex = leaderboardWithUsernames?.findIndex((entry) => entry.username?.toLowerCase() === b.toLowerCase());
// return (aIndex === -1 ? 10000000 : aIndex) - (bIndex === -1 ? 10000000 : bIndex);
// });

if (!editSessionIdOrAddress) return <></>;

Expand Down
Loading