The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: add filtering to counts query generation
TzeYiingf2380339ebbc
diff --git a/studio/components/interfaces/Settings/Logs/Logs.utils.ts b/studio/components/interfaces/Settings/Logs/Logs.utils.tsindex 22c495dd261..c989eba5d64 100644--- a/studio/components/interfaces/Settings/Logs/Logs.utils.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.utils.ts@@ -180,7 +180,9 @@ export const maybeShowUpgradePrompt = (return (day > 1 && tierKey === 'FREE') || (day > 7 && tierKey === 'PRO') || day > 90 && tierKey === 'ENTERPRISE'}-export const genCountQuery = (table: string): string => `SELECT count(*) as count FROM ${table}`+export const genCountQuery = (table: LogsTableName, filters: Filters): string => {+ const where = _genWhereStatement(table, filters)+ return `SELECT count(*) as count FROM ${table} ${where}`}/** calculates how much the chart start datetime should be offset given the current datetime filter params */export const calcChartStart = (params: Partial<LogsEndpointParams>): [Dayjs, string] => {diff --git a/studio/hooks/analytics/useLogsPreview.tsx b/studio/hooks/analytics/useLogsPreview.tsxindex 278a625cf5e..fc65f7288de 100644--- a/studio/hooks/analytics/useLogsPreview.tsx+++ b/studio/hooks/analytics/useLogsPreview.tsx@@ -111,7 +111,7 @@ function useLogsPreview(return `${API_URL}/projects/${projectRef}/analytics/endpoints/logs.all?${genQueryParams({...params,- sql: genCountQuery(table),+ sql: genCountQuery(table, filters),iso_timestamp_start: latestRefresh,} as any)}`}diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.jsindex 78bdae9d139..d6a6147ec6a 100644--- a/studio/tests/pages/projects/LogsPreviewer.test.js+++ b/studio/tests/pages/projects/LogsPreviewer.test.js@@ -369,6 +369,9 @@ test('filters alter generated query', async () => {userEvent.click(await screen.findByText(/Save/))await waitFor(() => {+ // counts are adjusted+ expect(get).toHaveBeenCalledWith(expect.stringMatching(/count.+\*.+as.count.+where.+500.+599/))+expect(get).toHaveBeenCalledWith(expect.stringContaining('500'))expect(get).toHaveBeenCalledWith(expect.stringContaining('599'))expect(get).toHaveBeenCalledWith(expect.stringContaining('200'))@@ -387,6 +390,11 @@ test('filters alter generated query', async () => {userEvent.click(await screen.findByText(/Save/))await waitFor(() => {+ // counts are adjusted+ expect(get).not.toHaveBeenCalledWith(expect.stringMatching(/count.+\*.+as.count.+where.+500.+599/))+ expect(get).toHaveBeenCalledWith(expect.stringMatching(/count.+\*.+as.count.+where.+400.+499/))++expect(get).not.toHaveBeenCalledWith(expect.stringContaining('500'))expect(get).not.toHaveBeenCalledWith(expect.stringContaining('599'))expect(get).not.toHaveBeenCalledWith(expect.stringContaining('200'))