Skip to content

Commit 5ecb360

Browse files
committed
chore: review pass
1 parent 4fcf4fe commit 5ecb360

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

apps/website/src/app/dashboard/[id]/settings/_components/GrantCard.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export function GrantCard({ guildId, grant }: GrantCardProps) {
4242
return (
4343
<div className="flex w-full flex-col gap-3 rounded-lg border border-on-secondary bg-card p-4 dark:border-on-secondary-dark dark:bg-card-dark">
4444
<div className="flex items-center gap-3">
45-
<UserAvatar className="h-12 w-12 rounded-full" isLoading={false} user={isUserObject ? user : undefined} />
45+
{isUserObject ? (
46+
<UserAvatar className="h-12 w-12 rounded-full" isLoading={false} user={user} />
47+
) : (
48+
<div className="h-12 w-12 shrink-0 rounded-full bg-on-tertiary dark:bg-on-tertiary-dark" />
49+
)}
4650
<div className="flex flex-col overflow-hidden">
4751
{globalName && (
4852
<p className="overflow-hidden overflow-ellipsis whitespace-nowrap text-lg font-medium text-primary dark:text-primary-dark">

services/api/src/routes/guilds/getGrants.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,27 @@ export default defineRoute({
3939
`;
4040

4141
const api = roundRobinAPI(req.guild!);
42+
const resolveCache = new Map<Snowflake, Promise<APIUser | Snowflake>>();
4243
const resolveUser = async (userId: Snowflake): Promise<APIUser | Snowflake> => {
43-
try {
44-
return await api.users.get(userId);
45-
} catch (error) {
46-
if (error instanceof DiscordAPIError && error.status === 404) {
47-
return userId;
44+
const cached = resolveCache.get(userId);
45+
if (cached) {
46+
return cached;
47+
}
48+
49+
const promise = (async () => {
50+
try {
51+
return await api.users.get(userId);
52+
} catch (error) {
53+
if (error instanceof DiscordAPIError && error.status === 404) {
54+
return userId;
55+
}
56+
57+
throw error;
4858
}
59+
})();
4960

50-
throw error;
51-
}
61+
resolveCache.set(userId, promise);
62+
return promise;
5263
};
5364

5465
const grants = await Promise.all(

0 commit comments

Comments
 (0)