mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
perf: pass org slug / project ref to resource warnings endpoint (#39471)
Based on https://github.com/supabase/infrastructure/pull/26483 - pass in project ref / org slug to ensure we filter down and not query across all orgs unnecessarily
This commit is contained in:
1 parent
fab4750d4d
commit
15c9a6ced3
15 files changed
+944
-406
No files matched your search
@@ -123,20 +123,24 @@ export const DestinationPanel = ({
|
||||
pipelineId: existingDestination?.pipelineId,
|
||||
})
|
||||
|
||||
const defaultValues = useMemo(
|
||||
() => ({
|
||||
const defaultValues = useMemo(() => {
|
||||
const bigQueryConfig =
|
||||
destinationData && 'big_query' in destinationData.config
|
||||
? destinationData?.config.big_query
|
||||
: null
|
||||
|
||||
return {
|
||||
type: TypeEnum.enum.BigQuery,
|
||||
name: destinationData?.name ?? '',
|
||||
projectId: destinationData?.config?.big_query?.project_id ?? '',
|
||||
datasetId: destinationData?.config?.big_query?.dataset_id ?? '',
|
||||
projectId: bigQueryConfig?.project_id ?? '',
|
||||
datasetId: bigQueryConfig?.dataset_id ?? '',
|
||||
// For now, the password will always be set as empty for security reasons.
|
||||
serviceAccountKey: destinationData?.config?.big_query?.service_account_key ?? '',
|
||||
serviceAccountKey: bigQueryConfig?.service_account_key ?? '',
|
||||
publicationName: pipelineData?.config.publication_name ?? '',
|
||||
maxFillMs: pipelineData?.config?.batch?.max_fill_ms,
|
||||
maxStalenessMins: destinationData?.config?.big_query?.max_staleness_mins,
|
||||
}),
|
||||
[destinationData, pipelineData]
|
||||
)
|
||||
maxStalenessMins: bigQueryConfig?.max_staleness_mins,
|
||||
}
|
||||
}, [destinationData, pipelineData])
|
||||
|
||||
const form = useForm<z.infer<typeof FormSchema>>({
|
||||
mode: 'onBlur',
|
||||
|
||||
@@ -159,7 +159,7 @@ export const Destinations = () => {
|
||||
sourceId={sourceId}
|
||||
destinationId={destination.id}
|
||||
destinationName={destination.name}
|
||||
type={destination.config.big_query ? 'BigQuery' : 'Other'}
|
||||
type={'big_query' in destination.config ? 'BigQuery' : 'Other'}
|
||||
pipeline={pipeline}
|
||||
error={pipelinesError}
|
||||
isLoading={isPipelinesLoading}
|
||||
|
||||
@@ -71,7 +71,8 @@ export function DiskManagementForm() {
|
||||
const { data: org } = useSelectedOrganizationQuery()
|
||||
const { setProjectStatus } = useSetProjectStatus()
|
||||
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery()
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery({ ref: projectRef })
|
||||
// [Joshen Cleanup] JFYI this client side filtering can be cleaned up once BE changes are live which will only return the warnings based on the provided ref
|
||||
const projectResourceWarnings = (resourceWarnings ?? [])?.find(
|
||||
(warning) => warning.project === project?.ref
|
||||
)
|
||||
|
||||
@@ -86,7 +86,7 @@ export const ProjectList = ({ organization: organization_, rewriteHref }: Projec
|
||||
isError: isErrorPermissions,
|
||||
error: permissionsError,
|
||||
} = usePermissionsQuery()
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery()
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery({ slug })
|
||||
|
||||
// Move all hooks to the top to comply with Rules of Hooks
|
||||
const { data: integrations } = useOrgIntegrationsQuery({ orgSlug: organization?.slug })
|
||||
|
||||
@@ -14,8 +14,9 @@ export const DatabaseReadOnlyAlert = () => {
|
||||
const { data: organization } = useSelectedOrganizationQuery()
|
||||
const [showConfirmationModal, setShowConfirmationModal] = useState(false)
|
||||
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery()
|
||||
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery({ ref: projectRef })
|
||||
// [Joshen Cleanup] JFYI this can be cleaned up once BE changes are live which will only return the warnings based on the provided ref
|
||||
// No longer need to filter by ref on the client side
|
||||
const isReadOnlyMode =
|
||||
(resourceWarnings ?? [])?.find((warning) => warning.project === projectRef)
|
||||
?.is_readonly_mode_enabled ?? false
|
||||
|
||||
+2
-1
@@ -59,7 +59,8 @@ export const InfrastructureActivity = () => {
|
||||
})
|
||||
const isFreePlan = organization?.plan?.id === 'free'
|
||||
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery()
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery({ ref: projectRef })
|
||||
// [Joshen Cleanup] JFYI this client side filtering can be cleaned up once BE changes are live which will only return the warnings based on the provided ref
|
||||
const projectResourceWarnings = resourceWarnings?.find((x) => x.project === projectRef)
|
||||
|
||||
const { data: addons } = useProjectAddonsQuery({ projectRef })
|
||||
|
||||
+2
-1
@@ -11,7 +11,8 @@ import { getWarningContent } from './ResourceExhaustionWarningBanner.utils'
|
||||
export const ResourceExhaustionWarningBanner = () => {
|
||||
const { ref } = useParams()
|
||||
const router = useRouter()
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery()
|
||||
const { data: resourceWarnings } = useResourceWarningsQuery({ ref: ref })
|
||||
// [Joshen Cleanup] JFYI this client side filtering can be cleaned up once BE changes are live which will only return the warnings based on the provided ref
|
||||
const projectResourceWarnings = (resourceWarnings ?? [])?.find(
|
||||
(warning) => warning.project === ref
|
||||
)
|
||||
|
||||
@@ -14,12 +14,12 @@ export async function checkGithubBranchValidity(
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
const { data, error } = await get(
|
||||
'/platform/integrations/github/repositories/{repositoryId}/branches/{branchName}',
|
||||
'/platform/integrations/github/repositories/{repository_id}/branches/{branch_name}',
|
||||
{
|
||||
params: {
|
||||
path: {
|
||||
repositoryId,
|
||||
branchName,
|
||||
repository_id: repositoryId,
|
||||
branch_name: branchName,
|
||||
},
|
||||
},
|
||||
signal,
|
||||
|
||||
@@ -13,8 +13,8 @@ export async function getGitHubBranches(
|
||||
) {
|
||||
if (!connectionId) throw new Error('connectionId is required')
|
||||
|
||||
const { data, error } = await get(`/platform/integrations/github/branches/{connectionId}`, {
|
||||
params: { path: { connectionId } },
|
||||
const { data, error } = await get(`/platform/integrations/github/branches/{connection_id}`, {
|
||||
params: { path: { connection_id: connectionId } },
|
||||
signal,
|
||||
})
|
||||
|
||||
|
||||
@@ -18,12 +18,12 @@ export async function updateInvoicePaymentLink({
|
||||
if (!invoiceId) throw new Error('Invoice ID is required')
|
||||
|
||||
const { data, error } = await get(
|
||||
'/platform/organizations/{slug}/billing/invoices/{invoiceId}/payment-link',
|
||||
'/platform/organizations/{slug}/billing/invoices/{invoice_id}/payment-link',
|
||||
{
|
||||
params: {
|
||||
path: {
|
||||
slug,
|
||||
invoiceId,
|
||||
invoice_id: invoiceId,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -12,10 +12,13 @@ export async function getInvoice({ invoiceId, slug }: InvoiceVariables, signal?:
|
||||
if (!invoiceId) throw new Error('Invoice ID is required')
|
||||
if (!slug) throw new Error('Slug is required')
|
||||
|
||||
const { data, error } = await get(`/platform/organizations/{slug}/billing/invoices/{invoiceId}`, {
|
||||
params: { path: { invoiceId, slug } },
|
||||
signal,
|
||||
})
|
||||
const { data, error } = await get(
|
||||
`/platform/organizations/{slug}/billing/invoices/{invoice_id}`,
|
||||
{
|
||||
params: { path: { invoice_id: invoiceId, slug } },
|
||||
signal,
|
||||
}
|
||||
)
|
||||
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
|
||||
@@ -2,5 +2,6 @@ export const usageKeys = {
|
||||
usage: (projectRef: string | undefined) => ['projects', projectRef, 'usage'] as const,
|
||||
orgUsage: (orgSlug: string | undefined, projectRef?: string, start?: string, end?: string) =>
|
||||
['organizations', orgSlug, 'usage', projectRef, start, end] as const,
|
||||
resourceWarnings: () => ['projects', 'resource-warnings'] as const,
|
||||
resourceWarnings: (slug?: string, projectRef?: string) =>
|
||||
['projects', 'resource-warnings', { slug, projectRef }] as const,
|
||||
}
|
||||
@@ -6,8 +6,24 @@ import { get, handleError } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { usageKeys } from './keys'
|
||||
|
||||
export async function getResourceWarnings(signal?: AbortSignal) {
|
||||
const { data, error } = await get(`/platform/projects-resource-warnings`, { signal })
|
||||
export type ResourceWarningsVariables = {
|
||||
ref?: string
|
||||
slug?: string
|
||||
}
|
||||
|
||||
export async function getResourceWarnings(
|
||||
variables?: ResourceWarningsVariables,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
const { data, error } = await get(`/platform/projects-resource-warnings`, {
|
||||
params: {
|
||||
query: {
|
||||
ref: variables?.ref,
|
||||
slug: variables?.slug,
|
||||
},
|
||||
},
|
||||
signal,
|
||||
})
|
||||
if (error) handleError(error)
|
||||
|
||||
return data
|
||||
@@ -17,15 +33,19 @@ export type ResourceWarning = components['schemas']['ProjectResourceWarningsResp
|
||||
export type ResourceWarningsData = Awaited<ReturnType<typeof getResourceWarnings>>
|
||||
export type ResourceWarningsError = ResponseError
|
||||
|
||||
export const useResourceWarningsQuery = <TData = ResourceWarningsData>({
|
||||
enabled = true,
|
||||
...options
|
||||
}: UseQueryOptions<ResourceWarningsData, ResourceWarningsError, TData> = {}) =>
|
||||
export const useResourceWarningsQuery = <TData = ResourceWarningsData>(
|
||||
variables: ResourceWarningsVariables,
|
||||
{
|
||||
enabled = true,
|
||||
...options
|
||||
}: UseQueryOptions<ResourceWarningsData, ResourceWarningsError, TData> = {}
|
||||
) =>
|
||||
useQuery<ResourceWarningsData, ResourceWarningsError, TData>(
|
||||
usageKeys.resourceWarnings(),
|
||||
({ signal }) => getResourceWarnings(signal),
|
||||
usageKeys.resourceWarnings(variables.slug, variables.ref),
|
||||
({ signal }) => getResourceWarnings(variables, signal),
|
||||
{
|
||||
enabled: IS_PLATFORM && enabled,
|
||||
enabled:
|
||||
IS_PLATFORM && enabled && (variables.ref !== undefined || variables.slug !== undefined),
|
||||
staleTime: 1000 * 60 * 60, // default 60 minutes
|
||||
...options,
|
||||
}
|
||||
|
||||
Vendored
+160
-7
@@ -1729,6 +1729,23 @@ export interface paths {
|
||||
patch?: never
|
||||
trace?: never
|
||||
}
|
||||
'/v1/projects/available-regions': {
|
||||
parameters: {
|
||||
query?: never
|
||||
header?: never
|
||||
path?: never
|
||||
cookie?: never
|
||||
}
|
||||
/** [Beta] Gets the list of available regions that can be used for a new project */
|
||||
get: operations['v1-get-available-regions']
|
||||
put?: never
|
||||
post?: never
|
||||
delete?: never
|
||||
options?: never
|
||||
head?: never
|
||||
patch?: never
|
||||
trace?: never
|
||||
}
|
||||
'/v1/snippets': {
|
||||
parameters: {
|
||||
query?: never
|
||||
@@ -1951,6 +1968,9 @@ export interface components {
|
||||
external_zoom_email_optional: boolean | null
|
||||
external_zoom_enabled: boolean | null
|
||||
external_zoom_secret: string | null
|
||||
hook_after_user_created_enabled: boolean | null
|
||||
hook_after_user_created_secrets: string | null
|
||||
hook_after_user_created_uri: string | null
|
||||
hook_before_user_created_enabled: boolean | null
|
||||
hook_before_user_created_secrets: string | null
|
||||
hook_before_user_created_uri: string | null
|
||||
@@ -2139,6 +2159,8 @@ export interface components {
|
||||
*/
|
||||
latest_check_run_id?: number
|
||||
name: string
|
||||
/** Format: uri */
|
||||
notify_url?: string
|
||||
parent_project_ref: string
|
||||
persistent: boolean
|
||||
/** Format: int32 */
|
||||
@@ -2232,6 +2254,11 @@ export interface components {
|
||||
| '48xlarge_high_memory'
|
||||
git_branch?: string
|
||||
is_default?: boolean
|
||||
/**
|
||||
* Format: uri
|
||||
* @description HTTP endpoint to receive branch status updates.
|
||||
*/
|
||||
notify_url?: string
|
||||
persistent?: boolean
|
||||
/**
|
||||
* @description Postgres engine version. If not provided, the latest version will be used.
|
||||
@@ -2900,10 +2927,11 @@ export interface components {
|
||||
redirect_uri?: string
|
||||
refresh_token?: string
|
||||
/**
|
||||
* Format: uri
|
||||
* @description Resource indicator for MCP (Model Context Protocol) clients
|
||||
* @enum {string}
|
||||
*/
|
||||
resource?: 'https://api.supabase.green/mcp' | 'https://mcp.supabase.green/mcp'
|
||||
resource?: string
|
||||
scope?: string
|
||||
}
|
||||
OAuthTokenResponse: {
|
||||
access_token: string
|
||||
@@ -2932,8 +2960,6 @@ export interface components {
|
||||
}[]
|
||||
/** @enum {string} */
|
||||
source_subscription_plan: 'free' | 'pro' | 'team' | 'enterprise'
|
||||
target_organization_eligible: boolean | null
|
||||
target_organization_has_free_project_slots: boolean | null
|
||||
/** @enum {string|null} */
|
||||
target_subscription_plan: 'free' | 'pro' | 'team' | 'enterprise' | null
|
||||
valid: boolean
|
||||
@@ -3028,6 +3054,46 @@ export interface components {
|
||||
override_active_until: string
|
||||
override_enabled: boolean
|
||||
}
|
||||
RegionsInfo: {
|
||||
all: {
|
||||
smartGroup: {
|
||||
/** @enum {string} */
|
||||
code: 'americas' | 'emea' | 'apac'
|
||||
name: string
|
||||
/** @enum {string} */
|
||||
type: 'smartGroup'
|
||||
}[]
|
||||
specific: {
|
||||
code: string
|
||||
name: string
|
||||
/** @enum {string} */
|
||||
provider: 'AWS' | 'FLY' | 'AWS_K8S' | 'AWS_NIMBUS'
|
||||
/** @enum {string} */
|
||||
status?: 'capacity' | 'other'
|
||||
/** @enum {string} */
|
||||
type: 'specific'
|
||||
}[]
|
||||
}
|
||||
recommendations: {
|
||||
smartGroup: {
|
||||
/** @enum {string} */
|
||||
code: 'americas' | 'emea' | 'apac'
|
||||
name: string
|
||||
/** @enum {string} */
|
||||
type: 'smartGroup'
|
||||
}
|
||||
specific: {
|
||||
code: string
|
||||
name: string
|
||||
/** @enum {string} */
|
||||
provider: 'AWS' | 'FLY' | 'AWS_K8S' | 'AWS_NIMBUS'
|
||||
/** @enum {string} */
|
||||
status?: 'capacity' | 'other'
|
||||
/** @enum {string} */
|
||||
type: 'specific'
|
||||
}[]
|
||||
}
|
||||
}
|
||||
RemoveNetworkBanRequest: {
|
||||
identifier?: string
|
||||
/** @description List of IP addresses to unban. */
|
||||
@@ -3332,6 +3398,9 @@ export interface components {
|
||||
external_zoom_email_optional?: boolean | null
|
||||
external_zoom_enabled?: boolean | null
|
||||
external_zoom_secret?: string | null
|
||||
hook_after_user_created_enabled?: boolean | null
|
||||
hook_after_user_created_secrets?: string | null
|
||||
hook_after_user_created_uri?: string | null
|
||||
hook_before_user_created_enabled?: boolean | null
|
||||
hook_before_user_created_secrets?: string | null
|
||||
hook_before_user_created_uri?: string | null
|
||||
@@ -3469,6 +3538,11 @@ export interface components {
|
||||
UpdateBranchBody: {
|
||||
branch_name?: string
|
||||
git_branch?: string
|
||||
/**
|
||||
* Format: uri
|
||||
* @description HTTP endpoint to receive branch status updates.
|
||||
*/
|
||||
notify_url?: string
|
||||
persistent?: boolean
|
||||
request_review?: boolean
|
||||
/**
|
||||
@@ -3751,10 +3825,17 @@ export interface components {
|
||||
*/
|
||||
plan?: 'free' | 'pro'
|
||||
/**
|
||||
* @description Region you want your server to reside in
|
||||
* @deprecated
|
||||
* @description Postgres engine version. If not provided, the latest version will be used.
|
||||
* @enum {string}
|
||||
*/
|
||||
region:
|
||||
postgres_engine?: '15' | '17' | '17-oriole'
|
||||
/**
|
||||
* @deprecated
|
||||
* @description Region you want your server to reside in. Use region_selection instead.
|
||||
* @enum {string}
|
||||
*/
|
||||
region?:
|
||||
| 'us-east-1'
|
||||
| 'us-east-2'
|
||||
| 'us-west-1'
|
||||
@@ -3773,6 +3854,54 @@ export interface components {
|
||||
| 'ca-central-1'
|
||||
| 'ap-south-1'
|
||||
| 'sa-east-1'
|
||||
/**
|
||||
* @description Region selection. Only one of region or region_selection can be specified.
|
||||
* @example { type: 'smartGroup', code: 'americas' }
|
||||
*/
|
||||
region_selection?:
|
||||
| {
|
||||
/**
|
||||
* @description Specific region code. The codes supported are not a stable API, and should be retrieved from the /available-regions endpoint.
|
||||
* @enum {string}
|
||||
*/
|
||||
code:
|
||||
| 'us-east-1'
|
||||
| 'us-east-2'
|
||||
| 'us-west-1'
|
||||
| 'us-west-2'
|
||||
| 'ap-east-1'
|
||||
| 'ap-southeast-1'
|
||||
| 'ap-northeast-1'
|
||||
| 'ap-northeast-2'
|
||||
| 'ap-southeast-2'
|
||||
| 'eu-west-1'
|
||||
| 'eu-west-2'
|
||||
| 'eu-west-3'
|
||||
| 'eu-north-1'
|
||||
| 'eu-central-1'
|
||||
| 'eu-central-2'
|
||||
| 'ca-central-1'
|
||||
| 'ap-south-1'
|
||||
| 'sa-east-1'
|
||||
/** @enum {string} */
|
||||
type: 'specific'
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* @description The Smart Region Group's code. The codes supported are not a stable API, and should be retrieved from the /available-regions endpoint.
|
||||
* @example apac
|
||||
* @enum {string}
|
||||
*/
|
||||
code: 'americas' | 'emea' | 'apac'
|
||||
/** @enum {string} */
|
||||
type: 'smartGroup'
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @description Release channel. If not provided, GA will be used.
|
||||
* @enum {string}
|
||||
*/
|
||||
release_channel?: 'internal' | 'alpha' | 'beta' | 'ga' | 'withdrawn' | 'preview'
|
||||
/**
|
||||
* Format: uri
|
||||
* @description Template URL used to create the project from the CLI.
|
||||
@@ -4322,7 +4451,7 @@ export interface operations {
|
||||
organization_slug?: string
|
||||
redirect_uri: string
|
||||
/** @description Resource indicator for MCP (Model Context Protocol) clients */
|
||||
resource?: 'https://api.supabase.green/mcp' | 'https://mcp.supabase.green/mcp'
|
||||
resource?: string
|
||||
response_mode?: string
|
||||
response_type: 'code' | 'token' | 'id_token token'
|
||||
scope?: string
|
||||
@@ -10675,6 +10804,30 @@ export interface operations {
|
||||
}
|
||||
}
|
||||
}
|
||||
'v1-get-available-regions': {
|
||||
parameters: {
|
||||
query: {
|
||||
/** @description Continent code to determine regional recommendations: NA (North America), SA (South America), EU (Europe), AF (Africa), AS (Asia), OC (Oceania), AN (Antarctica) */
|
||||
continent?: 'NA' | 'SA' | 'EU' | 'AF' | 'AS' | 'OC' | 'AN'
|
||||
/** @description Slug of your organization */
|
||||
organization_slug: string
|
||||
}
|
||||
header?: never
|
||||
path?: never
|
||||
cookie?: never
|
||||
}
|
||||
requestBody?: never
|
||||
responses: {
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown
|
||||
}
|
||||
content: {
|
||||
'application/json': components['schemas']['RegionsInfo']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'v1-list-all-snippets': {
|
||||
parameters: {
|
||||
query?: {
|
||||
|
||||
+715
-362
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user