useIsIndexAdvisorStatus.ts28 lines · main
| 1 | import { getIndexAdvisorExtensions } from '@/components/interfaces/QueryPerformance/IndexAdvisor/index-advisor.utils' |
| 2 | import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query' |
| 3 | import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' |
| 4 | |
| 5 | /** |
| 6 | * Hook to get both index advisor availability and enabled status |
| 7 | * |
| 8 | * available if the index_advisor and hypopg extensions are available |
| 9 | * enabled if the index_advisor and hypopg extensions are installed (their versions are not null) |
| 10 | */ |
| 11 | export function useIndexAdvisorStatus() { |
| 12 | const { data: project } = useSelectedProjectQuery() |
| 13 | const { data: extensions } = useDatabaseExtensionsQuery({ |
| 14 | projectRef: project?.ref, |
| 15 | connectionString: project?.connectionString, |
| 16 | }) |
| 17 | |
| 18 | const { hypopg, indexAdvisor } = getIndexAdvisorExtensions(extensions ?? []) |
| 19 | |
| 20 | const isIndexAdvisorAvailable = !!hypopg && !!indexAdvisor |
| 21 | |
| 22 | const isIndexAdvisorEnabled = |
| 23 | isIndexAdvisorAvailable && |
| 24 | hypopg.installed_version !== null && |
| 25 | indexAdvisor.installed_version !== null |
| 26 | |
| 27 | return { isIndexAdvisorAvailable, isIndexAdvisorEnabled } |
| 28 | } |