diff --git a/redisinsight/ui/src/packages/ri-explain/src/Explain.tsx b/redisinsight/ui/src/packages/ri-explain/src/Explain.tsx index 649afcbb06..740bdd3c5c 100644 --- a/redisinsight/ui/src/packages/ri-explain/src/Explain.tsx +++ b/redisinsight/ui/src/packages/ri-explain/src/Explain.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, useRef } from 'react' import { Model, Graph } from '@antv/x6' -import { register} from '@antv/x6-react-shape' +import { register } from '@antv/x6-react-shape' import Hierarchy from '@antv/hierarchy' import { formatRedisReply } from 'redisinsight-plugin-sdk' @@ -24,15 +24,16 @@ import { ParseExplain, ParseGraphV2, ParseProfile, - ParseProfileCluster, GetAncestors, GetTotalExecutionTime, + transformProfileResult, + findFlatProfile, } from './parser' import { ExplainNode, ProfileNode } from './Node' interface IExplain { command: string - data: [{response: string[] | string | any}] + data: [{ response: string[] | string | any }] } function getEdgeSize(c: number) { @@ -50,11 +51,11 @@ function getEdgeColor(isDarkTheme: boolean) { export default function Explain(props: IExplain): JSX.Element { const command = props.command.split(' ')[0].toLowerCase() if (command.startsWith('graph')) { - const info = props.data[0].response + const info = props.data[0].response const resp = ParseGraphV2(info) let profilingTime: IProfilingTime = {} - let t = command.endsWith('explain') ? CoreType.Explain : CoreType.Profile + const t = command.endsWith('explain') ? CoreType.Explain : CoreType.Profile if (t === CoreType.Profile) { profilingTime = { 'Total Execution Time': GetTotalExecutionTime(resp) @@ -76,7 +77,7 @@ export default function Explain(props: IExplain): JSX.Element { const [parsedRedisReply, setParsedRedisReply] = useState('') useEffect(() => { - if (command == 'ft.profile') { + if (command === 'ft.profile') { const getParsedResponse = async () => { const formattedResponse = await formatRedisReply(props.data[0].response, props.command) setParsedRedisReply(formattedResponse) @@ -85,54 +86,40 @@ export default function Explain(props: IExplain): JSX.Element { } }) - if (command == 'ft.profile') { - const info = props.data[0].response[1] + if (command === 'ft.profile') { + try { + const { data } = props + const isNewResponse = typeof data[0].response[1]?.[0] === 'string' - let data: EntityInfo - let profilingTime: IProfilingTime = {} + const [, profiles] = data[0].response || [] + const transformedProfiles = isNewResponse ? profiles : transformProfileResult(profiles) + const [shard] = findFlatProfile('Shards', transformedProfiles) + const profileInfo: EntityInfo = ParseProfile(shard) + + const profilingTime = { + 'Total Profile Time': findFlatProfile('Total Profile Time', shard), + 'Parsing Time': findFlatProfile('Parsing Time', shard), + 'Pipeline Creation Time': findFlatProfile('Pipeline Creation Time', shard), + } - if (info.length > 5 && typeof info[0] === 'string' && info[0].toLowerCase().startsWith('shard')) { - let [cluster, entityInfo] = ParseProfileCluster(info) - cluster['Coordinator'].forEach((kv: [string, string]) => profilingTime[kv[0]] = kv[1]) - data = entityInfo return ( - <> -