Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(data-warehouse): paginate schema list in source setup (#57196)

Marcus Hofcbef7b6d911d
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
index d1738b3b8f32..3ab9fb801ee2 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
@@ -280,7 +280,7 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
])
return (
- <div>
+ <div className="flex flex-col flex-1 min-h-0">
{!isWrapped && <BillingLimitNotice />}
<>
{showAccessMethodSelector && (
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index da5b7cef925e..169cecbeb68d 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -353,8 +353,9 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
}),
openSyncMethodModal: (schema: ExternalDataSourceSyncSchema) => ({ schema }),
cancelSyncMethodModal: true,
- toggleAllTables: (selectAll: boolean) => ({ selectAll }),
+ toggleAllTables: (selectAll: boolean, tableNames?: string[]) => ({ selectAll, tableNames }),
toggleDirectQuerySchemaGroup: (schemaName: string, shouldSync: boolean) => ({ schemaName, shouldSync }),
+ setSchemaNameFilter: (schemaNameFilter: string) => ({ schemaNameFilter }),
setExpandedDirectQuerySchemaKeys: (expandedSchemaKeys: string[]) => ({ expandedSchemaKeys }),
syncExpandedDirectQuerySchemaKeys: (groupedSchemaKeys: string[], fingerprint: string) => ({
groupedSchemaKeys,
@@ -438,10 +439,17 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
[] as ExternalDataSourceSyncSchema[],
{
setDatabaseSchemas: (_, { schemas }) => schemas,
- toggleAllTables: (state, { selectAll }) => {
+ toggleAllTables: (state, { selectAll, tableNames }) => {
+ if (!tableNames) {
+ return state.map((schema) => ({
+ ...schema,
+ should_sync: selectAll,
+ }))
+ }
+ const targetSet = new Set(tableNames)
return state.map((schema) => ({
...schema,
- should_sync: selectAll,
+ should_sync: targetSet.has(schema.table) ? selectAll : schema.should_sync,
}))
},
toggleSchemaShouldSync: (state, { schema, shouldSync }) => {
@@ -488,6 +496,14 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
clearSource: () => '',
},
],
+ schemaNameFilter: [
+ '',
+ {
+ setSchemaNameFilter: (_, { schemaNameFilter }) => schemaNameFilter,
+ onClear: () => '',
+ clearSource: () => '',
+ },
+ ],
source: [
{
payload: {},
@@ -861,11 +877,27 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
(s) => [s.manualLinkingProvider],
(manualLinkingProvider: ManualLinkSourceType | null): boolean => manualLinkingProvider !== null,
],
+ filteredDatabaseSchema: [
+ (s) => [s.databaseSchema, s.schemaNameFilter],
+ (
+ databaseSchema: ExternalDataSourceSyncSchema[],
+ schemaNameFilter: string
+ ): ExternalDataSourceSyncSchema[] => {
+ if (!schemaNameFilter) {
+ return databaseSchema
+ }
+ const filter = schemaNameFilter.toLowerCase()
+ return databaseSchema.filter((schema) => (schema.label ?? schema.table).toLowerCase().includes(filter))
+ },
+ ],
tablesAllToggledOn: [
- (s) => [s.databaseSchema],
- (databaseSchema: ExternalDataSourceSyncSchema[]): boolean | 'indeterminate' => {
- const enabledCount = databaseSchema.filter((schema) => schema.should_sync).length
- const totalCount = databaseSchema.length
+ (s) => [s.filteredDatabaseSchema],
+ (filteredDatabaseSchema: ExternalDataSourceSyncSchema[]): boolean | 'indeterminate' => {
+ if (filteredDatabaseSchema.length === 0) {
+ return false
+ }
+ const enabledCount = filteredDatabaseSchema.filter((schema) => schema.should_sync).length
+ const totalCount = filteredDatabaseSchema.length
return enabledCount === totalCount ? true : enabledCount > 0 ? 'indeterminate' : false
},
],
@@ -874,9 +906,9 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
(source): string | null => (typeof source.payload.schema === 'string' ? source.payload.schema : null),
],
groupedDirectQueryDatabaseSchema: [
- (s) => [s.databaseSchema, s.directQueryDefaultSchema],
- (databaseSchema, directQueryDefaultSchema) =>
- groupDirectQueryTablesBySchema(databaseSchema, directQueryDefaultSchema),
+ (s) => [s.filteredDatabaseSchema, s.directQueryDefaultSchema],
+ (filteredDatabaseSchema, directQueryDefaultSchema) =>
+ groupDirectQueryTablesBySchema(filteredDatabaseSchema, directQueryDefaultSchema),
],
groupedDirectQuerySchemaKeys: [
(s) => [s.groupedDirectQueryDatabaseSchema],
@@ -1427,13 +1459,10 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
})
}
},
- toggleAllTables: ({ selectAll }) => {
- actions.setDatabaseSchemas(
- values.databaseSchema.map((schema) => ({
- ...schema,
- should_sync: selectAll,
- }))
- )
+ toggleAllTables: () => {
+ // databaseSchema reducer already applied the toggle; re-emit so the
+ // setDatabaseSchemas listener (syncExpandedDirectQuerySchemaKeys) fires.
+ actions.setDatabaseSchemas(values.databaseSchema)
},
})),
tabAwareUrlToAction(({ actions, values }) => {
@@ -1478,7 +1507,6 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
// connector's defaults and restores any OAuth-saved form state — saved
// access_method wins over the URL one (the OAuth callback URL doesn't carry it).
actions.selectConnector(source, accessMethod)
- actions.updateSource({ access_method: accessMethod })
actions.handleRedirect(source.name)
actions.setStep(2)
return
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx b/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx
index 11535c3b46af..62b62a705bc0 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/SchemasTab.tsx
@@ -239,6 +239,7 @@ function ManagedSchemaTable({
dataSource={schemas}
loading={initialLoad}
disableTableWhileLoading={false}
+ pagination={{ pageSize: 100, hideOnSinglePage: true }}
columns={[
{
title: 'Schema',
diff --git a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx
index 615a1da0489f..80611dc5df96 100644
--- a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx
@@ -2,9 +2,19 @@ import { useActions, useValues } from 'kea'
import { useEffect } from 'react'
import { IconInfo, IconWarning } from '@posthog/icons'
-import { LemonButton, LemonCheckbox, LemonCollapse, LemonModal, LemonTable, LemonTag, Tooltip } from '@posthog/lemon-ui'
+import {
+ LemonButton,
+ LemonCheckbox,
+ LemonCollapse,
+ LemonInput,
+ LemonModal,
+ LemonTable,
+ LemonTag,
+ Tooltip,
+} from '@posthog/lemon-ui'
import { useFloatingContainer } from 'lib/hooks/useFloatingContainerContext'
+import { pluralize } from 'lib/utils'
import { ExternalDataSourceSyncSchema } from '~/types'
@@ -46,9 +56,12 @@ export default function SchemaForm(): JSX.Element {
toggleAllTables,
toggleDirectQuerySchemaGroup,
setExpandedDirectQuerySchemaKeys,
+ setSchemaNameFilter,
} = useActions(sourceWizardLogic)
const {
databaseSchema,
+ filteredDatabaseSchema,
+ schemaNameFilter,
suggestedTablesMap,
isDirectQueryMode,
source,
@@ -73,11 +86,32 @@ export default function SchemaForm(): JSX.Element {
}, [containerRef])
const showRows = databaseSchema.some((schema) => schema.rows != null)
+ const hasManySchemas = databaseSchema.length > 10
return (
<>
- <div className="flex flex-col gap-2">
- <div className="max-h-[60vh] overflow-y-auto">
+ <div className="flex flex-col gap-2 flex-1 min-h-0">
+ {hasManySchemas && (
+ <div className="flex items-center gap-2">
+ <LemonInput
+ type="search"
+ placeholder="Filter tables"
+ size="small"
+ value={schemaNameFilter}
+ onChange={setSchemaNameFilter}
+ />
+ <span className="text-muted text-sm">
+ {schemaNameFilter
+ ? `${filteredDatabaseSchema.length} of ${pluralize(
+ databaseSchema.length,
+ 'table',
+ 'tables'
+ )}`
+ : pluralize(databaseSchema.length, 'table', 'tables')}
+ </span>
+ </div>
+ )}
+ <div className="flex-1 min-h-0 overflow-y-auto">
{isDirectQueryMode ? (
groupedDirectQueryDatabaseSchema.length > 0 ? (
<div className="border rounded bg-bg-light">
@@ -193,14 +227,22 @@ export default function SchemaForm(): JSX.Element {
)
) : (
<LemonTable
- emptyState="No schemas found"
- dataSource={databaseSchema}
+ emptyState={schemaNameFilter ? `No tables match "${schemaNameFilter}"` : 'No schemas found'}
+ dataSource={filteredDatabaseSchema}
+ pagination={{ pageSize: 100, hideOnSinglePage: true }}
columns={[
{
title: (
<LemonCheckbox
checked={tablesAllToggledOn}
- onChange={(checked) => toggleAllTables(checked)}
+ onChange={(checked) =>
+ toggleAllTables(
+ checked,
+ schemaNameFilter
+ ? filteredDatabaseSchema.map((s) => s.table)
+ : undefined
+ )
+ }
/>
),
width: 0,