mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## Context Adds a source filter for the query performance advisor so you can filter out queries from the dashboard, or not from the dashboard <img width="309" height="217" alt="image" src="https://github.com/user-attachments/assets/c1fab9af-e57e-482f-afdb-d77a6600edb3" /> For transparency how this works: - Queries fired via the dashboard through the /query endpoint get enriched with metadata from the API to include a comment like `-- source: dashboard` - That's mainly how this filter works atm, to check if this comment exists if the source "Dashboard" is selected, and the inverse if the source "Non dashboard" is selected
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query'
|
|
import { useTableIndexAdvisor } from 'components/grid/context/TableIndexAdvisorContext'
|
|
import { databaseIndexesKeys } from 'data/database-indexes/keys'
|
|
import { databaseKeys } from 'data/database/keys'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { useRouter } from 'next/router'
|
|
import { parseAsString, useQueryStates } from 'nuqs'
|
|
import { useCallback } from 'react'
|
|
|
|
import {
|
|
QUERY_PERFORMANCE_PRESET_MAP,
|
|
QUERY_PERFORMANCE_REPORT_TYPES,
|
|
} from '../QueryPerformance.constants'
|
|
import { type QueryPerformanceSort } from '../QueryPerformance.types'
|
|
import { useQueryPerformanceQuery } from '../useQueryPerformanceQuery'
|
|
import { useIndexAdvisorStatus } from './useIsIndexAdvisorStatus'
|
|
|
|
export function useIndexInvalidation() {
|
|
const router = useRouter()
|
|
const queryClient = useQueryClient()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { isIndexAdvisorEnabled } = useIndexAdvisorStatus()
|
|
|
|
const [{ preset: urlPreset, search: searchQuery, order, sort }] = useQueryStates({
|
|
sort: parseAsString,
|
|
search: parseAsString.withDefault(''),
|
|
order: parseAsString,
|
|
preset: parseAsString.withDefault('unified'),
|
|
})
|
|
|
|
const { invalidate: invalidateTableIndexAdvisor } = useTableIndexAdvisor()
|
|
|
|
const preset = QUERY_PERFORMANCE_PRESET_MAP[urlPreset as QUERY_PERFORMANCE_REPORT_TYPES]
|
|
const orderBy = !!sort ? ({ column: sort, order } as QueryPerformanceSort) : undefined
|
|
const roles = router?.query?.roles ?? []
|
|
|
|
const queryPerformanceQuery = useQueryPerformanceQuery({
|
|
searchQuery,
|
|
orderBy,
|
|
preset,
|
|
roles: typeof roles === 'string' ? [roles] : roles,
|
|
runIndexAdvisor: isIndexAdvisorEnabled,
|
|
})
|
|
|
|
return useCallback(() => {
|
|
queryPerformanceQuery.runQuery()
|
|
queryClient.invalidateQueries({
|
|
queryKey: databaseKeys.indexAdvisorFromQuery(project?.ref, ''),
|
|
})
|
|
queryClient.invalidateQueries({ queryKey: databaseIndexesKeys.list(project?.ref) })
|
|
|
|
invalidateTableIndexAdvisor()
|
|
}, [queryPerformanceQuery, queryClient, project?.ref, invalidateTableIndexAdvisor])
|
|
}
|