The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Chore/optimize auth users UI query (#38739)
Joshen Lim87ab63a1d7f8
diff --git a/apps/studio/data/auth/users-infinite-query.ts b/apps/studio/data/auth/users-infinite-query.tsindex f64d68f7711..8fbf6d50ba0 100644--- a/apps/studio/data/auth/users-infinite-query.ts+++ b/apps/studio/data/auth/users-infinite-query.ts@@ -43,9 +43,6 @@ export const getUsersSQL = ({const hasValidKeywords = keywords && keywords !== ''const conditions: string[] = []- const baseQueryUsers = `- select *, coalesce((select array_agg(distinct i.provider) from auth.identities i where i.user_id = auth.users.id), '{}'::text[]) as providers from auth.users- `.trim()if (hasValidKeywords) {// [Joshen] Escape single quotes properly@@ -81,7 +78,52 @@ export const getUsersSQL = ({const sortOn = sort ?? 'created_at'const sortOrder = order ?? 'desc'- return `${baseQueryUsers}${conditions.length > 0 ? ` where ${combinedConditions}` : ''} order by "${sortOn}" ${sortOrder} nulls last limit ${USERS_PAGE_LIMIT} offset ${offset};`+ const usersQuery = `+with+ users_data as (+ select+ id,+ email,+ banned_until,+ created_at,+ confirmed_at,+ confirmation_sent_at,+ is_anonymous,+ is_sso_user,+ invited_at,+ last_sign_in_at,+ phone,+ raw_app_meta_data,+ raw_user_meta_data,+ updated_at+ from+ auth.users+ ${conditions.length > 0 ? ` where ${combinedConditions}` : ''}+ order by+ "${sortOn}" ${sortOrder} nulls last+ limit+ ${USERS_PAGE_LIMIT}+ offset+ ${offset}+ )+select+ *,+ coalesce(+ (+ select+ array_agg(distinct i.provider)+ from+ auth.identities i+ where+ i.user_id = users_data.id+ ),+ '{}'::text[]+ ) as providers+from+ users_data;+ `.trim()++ return usersQuery}export type UsersData = { result: User[] }