Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: break loop dependencies #771

Merged
merged 5 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions ui/lib/apps/SlowQuery/utils/tableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ function ResultStatusBadge({ status }: { status: 'success' | 'error' }) {
//////////////////////////////////////////
const TRANS_KEY_PREFIX = 'slow_query.fields'

export const derivedFields = {
cop_proc_avg: [
{ tooltipPrefix: 'mean', fieldName: 'cop_proc_avg' },
{ tooltipPrefix: 'max', fieldName: 'cop_proc_max' },
{ tooltipPrefix: 'p90', fieldName: 'cop_proc_p90' },
],
cop_wait_avg: [
{ tooltipPrefix: 'mean', fieldName: 'cop_wait_avg' },
{ tooltipPrefix: 'max', fieldName: 'cop_wait_max' },
{ tooltipPrefix: 'p90', fieldName: 'cop_wait_p90' },
],
}

//////////////////////////////////////////

export function slowQueryColumns(
rows: SlowquerySlowQuery[],
showFullSQL?: boolean
Expand Down Expand Up @@ -73,28 +88,8 @@ export function slowQueryColumns(
tcf.bar.single('commit_backoff_time', 'ns', rows),
tcf.bar.single('resolve_lock_time', 'ns', rows),
// cop
tcf.bar.multiple(
{
bars: [
{ mean: 'cop_proc_avg' },
{ max: 'cop_proc_max' },
{ p90: 'cop_proc_p90' },
],
},
'ns',
rows
),
tcf.bar.multiple(
{
bars: [
{ mean: 'cop_wait_avg' },
{ max: 'cop_wait_avg' },
{ p90: 'cop_wait_avg' },
],
},
'ns',
rows
),
tcf.bar.multiple({ sources: derivedFields.cop_proc_avg }, 'ns', rows),
tcf.bar.multiple({ sources: derivedFields.cop_wait_avg }, 'ns', rows),
// transaction
tcf.bar.single('write_keys', 'short', rows),
tcf.bar.single('write_size', 'bytes', rows),
Expand Down
16 changes: 7 additions & 9 deletions ui/lib/apps/SlowQuery/utils/useSlowQueryTableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import client, { ErrorStrategy, SlowquerySlowQuery } from '@lib/client'
import { calcTimeRange, TimeRange, IColumnKeys } from '@lib/components'
import useOrderState, { IOrderOptions } from '@lib/utils/useOrderState'

import { slowQueryColumns } from './tableColumns'
import { derivedFields, slowQueryColumns } from './tableColumns'
import { getSelectedFields } from '@lib/utils/tableColumnFactory'

export const DEF_SLOW_QUERY_COLUMN_KEYS: IColumnKeys = {
Expand Down Expand Up @@ -123,18 +123,16 @@ export default function useSlowQueryTableController(
querySchemas()
}, [])

// Notice: slowQueries, tableColumns, selectedFields make loop dependencies
const selectedFields = useMemo(
() => getSelectedFields(visibleColumnKeys, derivedFields).join(','),
[visibleColumnKeys]
)

const tableColumns = useMemo(
() => slowQueryColumns(slowQueries, showFullSQL),
[slowQueries, showFullSQL]
)
// make selectedFields as a string instead of an array to avoid infinite loop
// I have verified that it will cause infinite loop if we return selectedFields as an array
// so it is better to use the basic type (string, number...) instead of object as the dependency
const selectedFields = useMemo(
() => getSelectedFields(visibleColumnKeys, tableColumns).join(','),
[visibleColumnKeys, tableColumns]
)

useEffect(() => {
async function getSlowQueryList() {
setLoadingSlowQueries(true)
Expand Down
Loading