Skip to content

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

fix crash in query performance (#37758)

Jordi Enrica023a59ec598
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryCosts.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryCosts.tsx
index 7c92044d09d..197ab6ea489 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryCosts.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryCosts.tsx
@@ -24,17 +24,29 @@ export const QueryCosts = ({
<div className="flex flex-col items-end gap-y-1">
<div className="flex items-center gap-x-4">
<p className="text-sm text-foreground-light">Currently:</p>
- <p className="font-mono text-sm">{currentCost.toFixed(2)}</p>
+ <p className="font-mono text-sm">
+ {typeof currentCost === 'number' && !isNaN(currentCost) && isFinite(currentCost)
+ ? currentCost.toFixed(2)
+ : 'N/A'}
+ </p>
</div>
- {improvedCost && (
- <div className="flex items-center gap-x-4">
- <p className="text-sm text-foreground-light">With index:</p>
- <div className="flex items-center gap-x-2">
- <p className="font-mono text-sm">{improvedCost.toFixed(2)}</p>
- {improvement && <p className="text-sm text-brand">↓ {improvement.toFixed(1)}%</p>}
+ {improvedCost &&
+ typeof improvedCost === 'number' &&
+ !isNaN(improvedCost) &&
+ isFinite(improvedCost) && (
+ <div className="flex items-center gap-x-4">
+ <p className="text-sm text-foreground-light">With index:</p>
+ <div className="flex items-center gap-x-2">
+ <p className="font-mono text-sm">{improvedCost.toFixed(2)}</p>
+ {improvement &&
+ typeof improvement === 'number' &&
+ !isNaN(improvement) &&
+ isFinite(improvement) && (
+ <p className="text-sm text-brand">↓ {improvement.toFixed(1)}%</p>
+ )}
+ </div>
</div>
- </div>
- )}
+ )}
</div>
</div>
<button className="text-sm text-brand hover:text-brand-600 transition">View more</button>
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
index 2daa81f7149..d22830df4dd 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
@@ -76,10 +76,17 @@ export const QueryDetail = ({
{report
.filter((x) => x.id !== 'query')
.map((x) => {
+ const rawValue = selectedRow?.[x.id]
const isTime = x.name.includes('time')
+
const formattedValue = isTime
- ? `${selectedRow?.[x.id].toFixed(2)}ms`
- : String(selectedRow?.[x.id])
+ ? typeof rawValue === 'number' && !isNaN(rawValue) && isFinite(rawValue)
+ ? `${rawValue.toFixed(2)}ms`
+ : 'N/A'
+ : rawValue != null
+ ? String(rawValue)
+ : 'N/A'
+
return (
<div key={x.id} className="flex gap-x-2">
<p className="text-foreground-lighter text-sm w-32">{x.name}</p>
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx
index 9852385a20b..4cee87a3ece 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx
@@ -69,7 +69,7 @@ export const QueryPanelScoreSection = ({
) : (
<ArrowDown size={14} className="text-brand" />
)}
- {before !== 0 && (
+ {typeof before === 'number' && before !== 0 && !isNaN(before) && isFinite(before) && (
<span
className={cn(
'font-mono tracking-tighter',
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
index 127ec8dd8c8..d6f5d5a0b9d 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
@@ -91,11 +91,12 @@ export const QueryPerformanceGrid = ({ queryPerformanceQuery }: QueryPerformance
}
const isTime = col.name.includes('time')
- const formattedValue = !!value
- ? isTime
- ? `${value.toFixed(0)}ms`
- : value.toLocaleString()
- : ''
+ const formattedValue =
+ !!value && typeof value === 'number' && !isNaN(value) && isFinite(value)
+ ? isTime
+ ? `${value.toFixed(0)}ms`
+ : value.toLocaleString()
+ : ''
return (
<div
className={cn(
@@ -104,7 +105,9 @@ export const QueryPerformanceGrid = ({ queryPerformanceQuery }: QueryPerformance
)}
>
<p>{formattedValue}</p>
- {isTime && <p className="text-foreground-lighter">{(value / 1000).toFixed(2)}s</p>}
+ {isTime && typeof value === 'number' && !isNaN(value) && isFinite(value) && (
+ <p className="text-foreground-lighter">{(value / 1000).toFixed(2)}s</p>
+ )}
</div>
)
},