Skip to content

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

added log deduping and memoization

TzeYiing02ad7dba2f39
diff --git a/studio/components/interfaces/Settings/Logs/LogTable.tsx b/studio/components/interfaces/Settings/Logs/LogTable.tsx
index fb02efb0c98..9709dc6965d 100644
--- a/studio/components/interfaces/Settings/Logs/LogTable.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogTable.tsx
@@ -1,5 +1,5 @@
import dayjs from 'dayjs'
-import { useEffect, useState } from 'react'
+import { useEffect, useState, useMemo } from 'react'
import { Typography } from '@supabase/ui'
import DataGrid from '@supabase/react-data-grid'
@@ -43,10 +43,12 @@ const LogTable = ({ isCustomQuery, data }: Props) => {
},
}))
- const logMap = (data || []).reduce((acc: any, d) => {
- acc[d.id] = d
- return acc
- }, {})
+ const logMap: { [id: string]: LogData } = useMemo(() => {
+ return (data || []).reduce((acc: any, d) => {
+ acc[d.id] = d
+ return acc
+ }, {})
+ }, [JSON.stringify(data)])
useEffect(() => {
if (!data) return
@@ -60,6 +62,9 @@ const LogTable = ({ isCustomQuery, data }: Props) => {
// [Joshen] Hmm quite hacky now, but will do
const maxHeight = isCustomQuery ? 'calc(100vh - 42px - 10rem)' : 'calc(100vh - 42px - 3rem)'
+ const logDataRows = useMemo(() => {
+ return Object.values(logMap).sort((a, b) => a.timestamp - b.timestamp)
+ }, [JSON.stringify(Object.keys(logMap))])
return (
<section className="flex flex-1 flex-row" style={{ maxHeight }}>
<DataGrid
@@ -75,7 +80,7 @@ const LogTable = ({ isCustomQuery, data }: Props) => {
}
columns={columns as any}
rowClass={(r) => `${r.id === focusedLog?.id ? 'bg-green-800' : 'cursor-pointer'}`}
- rows={data}
+ rows={logDataRows}
rowKeyGetter={(r) => r.id}
onRowClick={(r) => setFocusedLog(logMap[r.id])}
/>
diff --git a/studio/tests/pages/projects/LogTable.test.js b/studio/tests/pages/projects/LogTable.test.js
index 51e2b439968..0bdcefa489d 100644
--- a/studio/tests/pages/projects/LogTable.test.js
+++ b/studio/tests/pages/projects/LogTable.test.js
@@ -16,3 +16,18 @@ test('can display log data', async () => {
await waitFor(() => screen.getByText(/my_key/))
await waitFor(() => screen.getByText(/something_value/))
})
+
+test ("dedupes log lines with exact id", async ()=>{
+ render(<LogTable data={[{
+ id: "seome-uuid",
+ timestamp: 1621323232312,
+ event_message: "some event happened",
+ },{
+ id: "seome-uuid",
+ timestamp: 1621323232312,
+ event_message: "some event happened",
+ }]} />)
+
+ // should only have one element, this line will fail if there are >1 element
+ await waitFor(() => screen.getByText(/happened/))
+})
\ No newline at end of file