Skip to content

Commit

Permalink
chore(dw-scheduled-mat-view-capture): Scheduled Materialized View Eve…
Browse files Browse the repository at this point in the history
…nt Capture (PostHog#28955)
  • Loading branch information
phixMe authored Feb 20, 2025
1 parent eeea5a6 commit 82164dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function InfoTab({ codeEditorKey }: InfoTabProps): JSX.Element {
id: editingView.id,
sync_frequency: newValue,
types: [[]],
lifecycle: 'update',
})
}
}}
Expand All @@ -125,14 +126,17 @@ export function InfoTab({ codeEditorKey }: InfoTabProps): JSX.Element {
you to run queries faster and more efficiently.
</p>
<LemonButton
onClick={() =>
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -58,7 +59,12 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
return values.dataWarehouseSavedQueries.filter((view) => view.id !== viewId)
},
updateDataWarehouseSavedQuery: async (
view: Partial<DatabaseSchemaViewTable> & { id: string; types: string[][]; sync_frequency?: string }
view: Partial<DatabaseSchemaViewTable> & {
id: string
types: string[][]
sync_frequency?: string
lifecycle?: string
}
) => {
const newView = await api.dataWarehouseSavedQueries.update(view.id, view)
return values.dataWarehouseSavedQueries.map((savedQuery) => {
Expand All @@ -75,7 +81,14 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
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')
},
Expand Down

0 comments on commit 82164dd

Please sign in to comment.