useQueryInsightsIssues.ts21 lines · main
| 1 | import { useMemo } from 'react' |
| 2 | |
| 3 | import type { QueryPerformanceRow } from '../../QueryPerformance/QueryPerformance.types' |
| 4 | import type { ClassifiedQuery } from '../QueryInsightsHealth/QueryInsightsHealth.types' |
| 5 | import { getQueryType } from '../QueryInsightsTable/QueryInsightsTable.utils' |
| 6 | import { classifyQuery } from './useQueryInsightsIssues.utils' |
| 7 | |
| 8 | export function useQueryInsightsIssues(data: QueryPerformanceRow[]) { |
| 9 | return useMemo(() => { |
| 10 | const classified: ClassifiedQuery[] = data.map((row) => { |
| 11 | const { issueType, hint } = classifyQuery(row) |
| 12 | return { ...row, issueType, hint, queryType: getQueryType(row.query) } |
| 13 | }) |
| 14 | |
| 15 | const errors = classified.filter((q) => q.issueType === 'error') |
| 16 | const indexIssues = classified.filter((q) => q.issueType === 'index') |
| 17 | const slowQueries = classified.filter((q) => q.issueType === 'slow') |
| 18 | |
| 19 | return { classified, errors, indexIssues, slowQueries } |
| 20 | }, [data]) |
| 21 | } |