Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): combine time consumed cols in query perf (#38920)

kemal.earth73b0b21bb70c
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
index 7c68d531f80..b792220b714 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
@@ -2,7 +2,6 @@ import { Lightbulb } from 'lucide-react'
import { useEffect, useState } from 'react'
import dynamic from 'next/dynamic'
import dayjs from 'dayjs'
-import duration from 'dayjs/plugin/duration'
import { formatSql } from 'lib/formatSql'
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, cn } from 'ui'
@@ -97,43 +96,31 @@ export const QueryDetail = ({ selectedRow, onClickViewSuggestion }: QueryDetailP
: 'n/a'
if (x.id === 'prop_total_time') {
- return (
- <li key={x.id} className="flex justify-between pt-3 text-sm">
- <p className="text-foreground-light">{x.name}</p>
- {rawValue ? (
- <p
- className={cn(
- 'tabular-nums',
- rawValue.toFixed(1) === '0.0' && 'text-foreground-lighter'
- )}
- >
- {rawValue.toFixed(1)}%
- </p>
- ) : (
- <p className="text-muted">&ndash;</p>
- )}
- </li>
- )
- }
+ const percentage = selectedRow?.prop_total_time || 0
+ const totalTime = selectedRow?.total_time || 0
- if (x.id == 'total_time') {
return (
<li key={x.id} className="flex justify-between pt-3 text-sm">
- <p className="text-foreground-light">
- {x.name + ' '}
- <span className="text-foreground-lighter">latency</span>
- </p>
- {isTime &&
- typeof rawValue === 'number' &&
- !isNaN(rawValue) &&
- isFinite(rawValue) ? (
- <p
- className={cn(
- 'tabular-nums',
- formatDuration(rawValue / 1000) === '0.0s' && 'text-foreground-lighter'
- )}
- >
- {formatDuration(rawValue / 1000)}
+ <p className="text-foreground-light">{x.name}</p>
+ {percentage && totalTime ? (
+ <p className="flex items-center gap-x-1.5">
+ <span
+ className={cn(
+ 'tabular-nums',
+ percentage.toFixed(1) === '0.0' && 'text-foreground-lighter'
+ )}
+ >
+ {percentage.toFixed(1)}%
+ </span>{' '}
+ <span className="text-muted">/</span>{' '}
+ <span
+ className={cn(
+ 'tabular-nums',
+ formatDuration(rawValue / 1000) === '0.00s' && 'text-foreground-lighter'
+ )}
+ >
+ {formatDuration(totalTime / 1000)}
+ </span>
</p>
) : (
<p className="text-muted">&ndash;</p>
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.constants.ts b/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.constants.ts
index a09da9a32b1..4b96763edfa 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.constants.ts
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.constants.ts
@@ -14,8 +14,7 @@ export const QUERY_PERFORMANCE_PRESET_MAP = {
export const QUERY_PERFORMANCE_COLUMNS = [
{ id: 'query', name: 'Query', description: undefined, minWidth: 500 },
- { id: 'prop_total_time', name: 'Time consumed', description: undefined, minWidth: 130 },
- { id: 'total_time', name: 'Total time', description: 'latency', minWidth: 150 },
+ { id: 'prop_total_time', name: 'Time consumed', description: undefined, minWidth: 150 },
{ id: 'calls', name: 'Count', description: undefined, minWidth: 100 },
{ id: 'max_time', name: 'Max time', description: undefined, minWidth: 100 },
{ id: 'mean_time', name: 'Mean time', description: undefined, minWidth: 100 },
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
index 36cadf22a86..62e3bb49732 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
@@ -141,51 +141,48 @@ export const QueryPerformanceGrid = ({ queryPerformanceQuery }: QueryPerformance
)
}
+ const isTime = col.name.includes('time')
+ const formattedValue =
+ !!value && typeof value === 'number' && !isNaN(value) && isFinite(value)
+ ? isTime
+ ? `${value.toFixed(0).toLocaleString()}ms`
+ : value.toLocaleString()
+ : ''
+
if (col.id === 'prop_total_time') {
const percentage = props.row.prop_total_time || 0
+ const totalTime = props.row.total_time || 0
const fillWidth = Math.min(percentage, 100)
return (
<div className="w-full flex flex-col justify-center text-xs text-right tabular-nums font-mono">
<div
- className={`absolute inset-0 bg-foreground transition-all duration-200 z-0`}
+ className="absolute inset-0 bg-foreground transition-all duration-200 z-0"
style={{
width: `${fillWidth}%`,
opacity: 0.04,
}}
/>
- {value ? (
- <p className={cn(value.toFixed(1) === '0.0' && 'text-foreground-lighter')}>
- {value.toFixed(1)}%
- </p>
- ) : (
- <p className="text-muted">&ndash;</p>
- )}
- </div>
- )
- }
-
- const isTime = col.name.includes('time')
- const formattedValue =
- !!value && typeof value === 'number' && !isNaN(value) && isFinite(value)
- ? isTime
- ? `${value.toFixed(0).toLocaleString()}ms`
- : value.toLocaleString()
- : ''
-
- if (col.id === 'total_time') {
- return (
- <div className="w-full flex flex-col justify-center text-xs text-right tabular-nums font-mono">
- {isTime && typeof value === 'number' && !isNaN(value) && isFinite(value) ? (
- <p
- className={cn((value / 1000).toFixed(2) === '0.00' && 'text-foreground-lighter')}
- >
- {(value / 1000).toLocaleString(undefined, {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- })}
- s
- </p>
+ {percentage && totalTime ? (
+ <span className="flex items-center justify-end gap-x-1.5">
+ <span
+ className={cn(percentage.toFixed(1) === '0.0' && 'text-foreground-lighter')}
+ >
+ {percentage.toFixed(1)}%
+ </span>{' '}
+ <span className="text-muted">/</span>
+ <span
+ className={cn(
+ (totalTime / 1000).toFixed(2) === '0.00' && 'text-foreground-lighter'
+ )}
+ >
+ {(totalTime / 1000).toLocaleString(undefined, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ s
+ </span>
+ </span>
) : (
<p className="text-muted">&ndash;</p>
)}