From 82164dd07579df93c94a0177f3ab893db6557853 Mon Sep 17 00:00:00 2001 From: Peter Hicks Date: Thu, 20 Feb 2025 08:39:47 -0800 Subject: [PATCH] chore(dw-scheduled-mat-view-capture): Scheduled Materialized View Event Capture (#28955) --- .../editor/OutputPaneTabs/InfoTab.tsx | 20 +++++++++++-------- .../saved_queries/dataWarehouseViewsLogic.tsx | 17 ++++++++++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/InfoTab.tsx b/frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/InfoTab.tsx index 60b13f67b93cc..8a2b35cb1add3 100644 --- a/frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/InfoTab.tsx +++ b/frontend/src/scenes/data-warehouse/editor/OutputPaneTabs/InfoTab.tsx @@ -110,6 +110,7 @@ export function InfoTab({ codeEditorKey }: InfoTabProps): JSX.Element { id: editingView.id, sync_frequency: newValue, types: [[]], + lifecycle: 'update', }) } }} @@ -125,14 +126,17 @@ export function InfoTab({ codeEditorKey }: InfoTabProps): JSX.Element { you to run queries faster and more efficiently.

- editingView && - updateDataWarehouseSavedQuery({ - id: editingView.id, - sync_frequency: '24hour', - types: [[]], - }) - } + onClick={() => { + return ( + editingView && + updateDataWarehouseSavedQuery({ + id: editingView.id, + sync_frequency: '24hour', + types: [[]], + lifecycle: 'create', + }) + ) + }} type="primary" disabledReason={editingView ? undefined : 'You must save the view first'} loading={updatingDataWarehouseSavedQuery} diff --git a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx index ab6e4689e059f..d92594ae8d6fe 100644 --- a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx +++ b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx @@ -2,6 +2,7 @@ import { lemonToast } from '@posthog/lemon-ui' import { actions, connect, events, kea, listeners, path, reducers, selectors } from 'kea' import { loaders } from 'kea-loaders' import api from 'lib/api' +import posthog from 'posthog-js' import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic' import { userLogic } from 'scenes/userLogic' @@ -58,7 +59,12 @@ export const dataWarehouseViewsLogic = kea([ return values.dataWarehouseSavedQueries.filter((view) => view.id !== viewId) }, updateDataWarehouseSavedQuery: async ( - view: Partial & { id: string; types: string[][]; sync_frequency?: string } + view: Partial & { + id: string + types: string[][] + sync_frequency?: string + lifecycle?: string + } ) => { const newView = await api.dataWarehouseSavedQueries.update(view.id, view) return values.dataWarehouseSavedQueries.map((savedQuery) => { @@ -75,7 +81,14 @@ export const dataWarehouseViewsLogic = kea([ createDataWarehouseSavedQuerySuccess: () => { actions.loadDatabase() }, - updateDataWarehouseSavedQuerySuccess: () => { + updateDataWarehouseSavedQuerySuccess: ({ payload }) => { + // in the case where we are scheduling a materialized view, send an event + if (payload && payload.lifecycle && payload.sync_frequency) { + // this function exists as an upsert, so we need to check if the view was created or updated + posthog.capture(`materialized view ${payload.lifecycle === 'update' ? 'updated' : 'created'}`, { + sync_frequency: payload.sync_frequency, + }) + } actions.loadDatabase() lemonToast.success('View updated') },