Fix: Handle RPC errors gracefully

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 19:07:38 +00:00
parent 16940419e5
commit ff2215f450
4 changed files with 100 additions and 27 deletions

View File

@@ -768,10 +768,19 @@ export async function fetchSystemActivities(
const uniqueUserIds = [...new Set(filteredActivities.map(a => a.actor_id).filter(Boolean))] as string[];
if (uniqueUserIds.length > 0) {
const { data: allProfiles } = await supabase
let profiles: Array<{ user_id: string; username: string; display_name?: string | null; avatar_url?: string | null }> | null = null;
const { data: allProfiles, error: rpcError } = await supabase
.rpc('get_users_with_emails');
const profiles = allProfiles?.filter(p => uniqueUserIds.includes(p.user_id));
if (rpcError) {
const { data: basicProfiles } = await supabase
.from('profiles')
.select('user_id, username, display_name, avatar_url')
.in('user_id', uniqueUserIds);
profiles = basicProfiles as typeof profiles;
} else {
profiles = allProfiles?.filter(p => uniqueUserIds.includes(p.user_id)) || null;
}
if (profiles) {
const profileMap = new Map(profiles.map(p => [p.user_id, p]));
@@ -797,10 +806,19 @@ export async function fetchSystemActivities(
.filter(Boolean) as string[];
if (targetUserIds.length > 0) {
const { data: allTargetProfiles } = await supabase
let targetProfiles: Array<{ user_id: string; username: string; display_name?: string | null }> | null = null;
const { data: allTargetProfiles, error: targetRpcError } = await supabase
.rpc('get_users_with_emails');
const targetProfiles = allTargetProfiles?.filter(p => targetUserIds.includes(p.user_id));
if (targetRpcError) {
const { data: basicProfiles } = await supabase
.from('profiles')
.select('user_id, username, display_name')
.in('user_id', targetUserIds);
targetProfiles = basicProfiles as typeof targetProfiles;
} else {
targetProfiles = allTargetProfiles?.filter(p => targetUserIds.includes(p.user_id)) || null;
}
if (targetProfiles) {
const targetProfileMap = new Map(targetProfiles.map(p => [p.user_id, p]));
@@ -826,10 +844,19 @@ export async function fetchSystemActivities(
.filter(Boolean) as string[];
if (accountUserIds.length > 0) {
const { data: allAccountProfiles } = await supabase
let accountProfiles: Array<{ user_id: string; username: string; display_name?: string | null }> | null = null;
const { data: allAccountProfiles, error: accountRpcError } = await supabase
.rpc('get_users_with_emails');
const accountProfiles = allAccountProfiles?.filter(p => accountUserIds.includes(p.user_id));
if (accountRpcError) {
const { data: basicProfiles } = await supabase
.from('profiles')
.select('user_id, username, display_name')
.in('user_id', accountUserIds);
accountProfiles = basicProfiles as typeof accountProfiles;
} else {
accountProfiles = allAccountProfiles?.filter(p => accountUserIds.includes(p.user_id)) || null;
}
if (accountProfiles) {
const accountProfileMap = new Map(accountProfiles.map(p => [p.user_id, p]));