mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 20:35:07 +03:00
* Update * Clean up + fix UI * Add data values to tab * Add comment * Format sql query in query details * Clean uo * Deprecate old files * Address comments * chore: update styles (#22591) * Midway integrating index advisor * Add feature flag, reinstate old UI for feature flag * First iteration of integrating index advisor * Add more details in index advisor and add feature flag * Shift explain_query function into pg_temp * Clean uo * fix padding * Update apps/studio/components/interfaces/QueryPerformanceV2/QueryPanel.tsx Co-authored-by: Alaister Young <alaister@users.noreply.github.com> * Update UI * Address some feedback * Moar addressing feedback * Update docs url --------- Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com> Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import { ExternalLink } from 'lucide-react'
|
|
|
|
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
|
|
import { useDatabaseExtensionEnableMutation } from 'data/database-extensions/database-extension-enable-mutation'
|
|
import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
|
|
import { useIndexAdvisorEnableMutation } from 'data/database/index-advisor-enable-mutation'
|
|
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
|
|
import { Markdown } from '../Markdown'
|
|
|
|
export const IndexAdvisorDisabledState = () => {
|
|
const { project } = useProjectContext()
|
|
const { data: extensions } = useDatabaseExtensionsQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
const hypopgExtension = (extensions ?? []).find((ext) => ext.name === 'hypopg')
|
|
|
|
const { mutateAsync: enableExtension, isLoading: isEnablingExtension } =
|
|
useDatabaseExtensionEnableMutation()
|
|
const { mutateAsync: enableIndexAdvisor, isLoading: isEnablingIndexAdvisor } =
|
|
useIndexAdvisorEnableMutation()
|
|
const isEnabling = isEnablingExtension || isEnablingIndexAdvisor
|
|
|
|
const onEnableIndexAdvisor = async () => {
|
|
if (project === undefined) return console.error('Project is required')
|
|
if (hypopgExtension?.installed_version === null) {
|
|
await enableExtension({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
name: hypopgExtension.name,
|
|
schema: hypopgExtension?.schema ?? 'extensions',
|
|
version: hypopgExtension.default_version,
|
|
})
|
|
}
|
|
|
|
// [Joshen] Once index_advisor ext is ready, it'll just be enabling an extension
|
|
await enableIndexAdvisor({
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Alert_Shadcn_>
|
|
<AlertTitle_Shadcn_>
|
|
Get index suggestions to improve your query performance
|
|
</AlertTitle_Shadcn_>
|
|
<AlertDescription_Shadcn_>
|
|
<Markdown content="The `index_advisor` extension can help in recommending database indexes to reduce the costs of your query." />
|
|
</AlertDescription_Shadcn_>
|
|
<AlertDescription_Shadcn_ className="mt-3">
|
|
<div className="flex items-center gap-x-2">
|
|
<Button
|
|
type="default"
|
|
disabled={isEnabling}
|
|
loading={isEnabling}
|
|
onClick={() => onEnableIndexAdvisor()}
|
|
>
|
|
Enable index advisor
|
|
</Button>
|
|
<Button asChild type="default" icon={<ExternalLink />}>
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
href="https://supabase.com/docs/guides/database/extensions/index_advisor"
|
|
>
|
|
Documentation
|
|
</a>
|
|
</Button>
|
|
</div>
|
|
</AlertDescription_Shadcn_>
|
|
</Alert_Shadcn_>
|
|
)
|
|
}
|