Files
supabase/apps/studio/data/config/pgbouncer-enabled-query.ts
Alaister YoungandJoshen Lim 3a27070dc2 chore(perf): table editor query optimisation (#30184)
* chore: table editor query optimisation

* removed unused queries and fix invalidations

* address feedback

* fix filtering for foreign tables

* Update

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-10-31 15:20:40 +08:00

42 lines
1.4 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError } from 'types'
import { configKeys } from './keys'
type PgBouncerVariables = {
projectRef?: string
}
// This API call describes whether PgBouncer is still present on the instance. Eventually PgBouncer will be removed.
export async function getPgBouncerStatus({ projectRef }: PgBouncerVariables, signal?: AbortSignal) {
if (projectRef === undefined) throw new Error('Project ref is required')
const { data, error } = await get('/platform/projects/{ref}/config/pgbouncer/status', {
params: { path: { ref: projectRef } },
})
if (error) handleError(error)
return data
}
export type PgBouncerStatusData = Awaited<ReturnType<typeof getPgBouncerStatus>>
export type PgBouncerStatusError = ResponseError
export const usePgBouncerStatus = <TData = PgBouncerStatusData>(
{ projectRef }: PgBouncerVariables,
{
enabled = true,
...options
}: UseQueryOptions<PgBouncerStatusData, PgBouncerStatusError, TData> = {}
) =>
useQuery<PgBouncerStatusData, PgBouncerStatusError, TData>(
configKeys.pgBouncerStatus(projectRef),
({ signal }) => getPgBouncerStatus({ projectRef }, signal),
{
enabled: enabled && IS_PLATFORM && typeof projectRef !== 'undefined',
...options,
}
)