perf(web): reduce member profile roundtrips in chat info
Some checks are pending
CI / test (push) Has started running

This commit is contained in:
2026-03-08 21:33:11 +03:00
parent cb37e735b0
commit 3506231295
3 changed files with 28 additions and 5 deletions

View File

@@ -46,6 +46,9 @@ export interface ChatMember {
user_id: number;
role: ChatMemberRole;
joined_at: string;
username?: string | null;
name?: string | null;
avatar_url?: string | null;
}
export interface ChatBan {

View File

@@ -134,11 +134,31 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
async function refreshMembers(targetChatId: number): Promise<ChatMember[]> {
const nextMembers = await listChatMembers(targetChatId);
setMembers(nextMembers);
const ids = [...new Set(nextMembers.map((m) => m.user_id))];
const profiles = await Promise.all(ids.map((id) => getUserById(id)));
const byId: Record<number, AuthUser> = {};
for (const profile of profiles) {
byId[profile.id] = profile;
const missingIds: number[] = [];
for (const member of nextMembers) {
if (member.name || member.username || member.avatar_url) {
byId[member.user_id] = {
id: member.user_id,
email: "",
name: member.name || member.username || `user #${member.user_id}`,
username: member.username || `user${member.user_id}`,
bio: null,
avatar_url: member.avatar_url || null,
email_verified: false,
allow_private_messages: true,
created_at: "",
updated_at: "",
};
} else {
missingIds.push(member.user_id);
}
}
if (missingIds.length) {
const profiles = await Promise.all(missingIds.map((id) => getUserById(id)));
for (const profile of profiles) {
byId[profile.id] = profile;
}
}
setMemberUsers(byId);
return nextMembers;