Refactor: Use RPC for user data

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 18:36:45 +00:00
parent bcbb8019bd
commit a5d0d2253e
4 changed files with 36 additions and 30 deletions

View File

@@ -190,11 +190,11 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
// Get unique reporter IDs
const reporterIds = [...new Set((data || []).map(r => r.reporter_id))];
// Fetch reporter profiles
const { data: profiles } = await supabase
.from('profiles')
.select('user_id, username, display_name')
.in('user_id', reporterIds);
// Fetch reporter profiles with emails (for admins)
const { data: allProfiles } = await supabase
.rpc('get_users_with_emails');
const profiles = allProfiles?.filter(p => reporterIds.includes(p.user_id));
const profileMap = new Map(profiles?.map(p => [p.user_id, p]) || []);
@@ -219,10 +219,8 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
profileIds.length > 0
? supabase
.from('profiles')
.select('user_id, username, display_name')
.in('user_id', profileIds)
.then(({ data }) => data || [])
.rpc('get_users_with_emails')
.then(({ data }) => data?.filter(p => profileIds.includes(p.user_id)) || [])
: Promise.resolve([]),
submissionIds.length > 0