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.

feat(data-warehouse): cache slack channel listing per access token (#57966)

Marcus Hof38e2cbc2d3bf
diff --git a/posthog/temporal/data_imports/sources/ashby/source.py b/posthog/temporal/data_imports/sources/ashby/source.py
index ab62c6af3994..eeb48c5dab93 100644
--- a/posthog/temporal/data_imports/sources/ashby/source.py
+++ b/posthog/temporal/data_imports/sources/ashby/source.py
@@ -43,7 +43,12 @@ class AshbySource(SimpleSource[AshbySourceConfig]):
raise NotImplementedError()
def get_schemas(
- self, config: AshbySourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: AshbySourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
raise NotImplementedError()
diff --git a/posthog/temporal/data_imports/sources/attio/source.py b/posthog/temporal/data_imports/sources/attio/source.py
index 341688f9d816..5c895912e708 100644
--- a/posthog/temporal/data_imports/sources/attio/source.py
+++ b/posthog/temporal/data_imports/sources/attio/source.py
@@ -68,7 +68,12 @@ You can generate an API key in your Attio workspace settings. Check out [this gu
)
def get_schemas(
- self, config: AttioSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: AttioSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
# Attio API doesn't support updatedAt filtering, so only full refresh is supported
schemas = [
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.py
index bc2a22507339..aa03999a30a8 100644
--- a/posthog/temporal/data_imports/sources/bigquery/source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/source.py
@@ -49,7 +49,12 @@ class BigQuerySource(SimpleSource[BigQuerySourceConfig]):
}
def get_schemas(
- self, config: BigQuerySourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: BigQuerySourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
bq_schemas = get_bigquery_schemas(
config,
diff --git a/posthog/temporal/data_imports/sources/bing_ads/source.py b/posthog/temporal/data_imports/sources/bing_ads/source.py
index 950e6eadba54..655f131d29f2 100644
--- a/posthog/temporal/data_imports/sources/bing_ads/source.py
+++ b/posthog/temporal/data_imports/sources/bing_ads/source.py
@@ -94,7 +94,12 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], O
return False, f"Failed to validate Bing Ads credentials: {str(e)}"
def get_schemas(
- self, config: BingAdsSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: BingAdsSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
bing_ads_schemas = get_schemas()
ads_incremental_fields = get_incremental_fields()
diff --git a/posthog/temporal/data_imports/sources/buildbetter/source.py b/posthog/temporal/data_imports/sources/buildbetter/source.py
index c4c6bc4507a0..2f453847b565 100644
--- a/posthog/temporal/data_imports/sources/buildbetter/source.py
+++ b/posthog/temporal/data_imports/sources/buildbetter/source.py
@@ -37,7 +37,12 @@ class BuildBetterSource(ResumableSource[BuildBetterSourceConfig, BuildBetterResu
}
def get_schemas(
- self, config: BuildBetterSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: BuildBetterSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/chargebee/source.py b/posthog/temporal/data_imports/sources/chargebee/source.py
index 52f0472c0908..ed27dfd87806 100644
--- a/posthog/temporal/data_imports/sources/chargebee/source.py
+++ b/posthog/temporal/data_imports/sources/chargebee/source.py
@@ -37,7 +37,12 @@ class ChargebeeSource(ResumableSource[ChargebeeSourceConfig, ChargebeeResumeConf
}
def get_schemas(
- self, config: ChargebeeSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: ChargebeeSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/clerk/source.py b/posthog/temporal/data_imports/sources/clerk/source.py
index ec7db6e1fec4..d1bdcc78bd99 100644
--- a/posthog/temporal/data_imports/sources/clerk/source.py
+++ b/posthog/temporal/data_imports/sources/clerk/source.py
@@ -58,7 +58,12 @@ The secret key starts with `sk_live_`.
)
def get_schemas(
- self, config: ClerkSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: ClerkSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
# Clerk only supports full refresh - the API doesn't support filtering by updated_at
schemas = [
diff --git a/posthog/temporal/data_imports/sources/clickhouse/source.py b/posthog/temporal/data_imports/sources/clickhouse/source.py
index c835c93c136a..e6b1319d50a7 100644
--- a/posthog/temporal/data_imports/sources/clickhouse/source.py
+++ b/posthog/temporal/data_imports/sources/clickhouse/source.py
@@ -165,6 +165,7 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas: list[SourceSchema] = []
diff --git a/posthog/temporal/data_imports/sources/common/base.py b/posthog/temporal/data_imports/sources/common/base.py
index 120aeab7fbe9..65967a3ce652 100644
--- a/posthog/temporal/data_imports/sources/common/base.py
+++ b/posthog/temporal/data_imports/sources/common/base.py
@@ -75,8 +75,19 @@ class _BaseSource(ABC, Generic[ConfigType]):
return {}
def get_schemas(
- self, config: ConfigType, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: ConfigType,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
+ """Return the list of schemas available for this source.
+
+ ``force_refresh=True`` instructs the source to bypass any internal cache
+ of upstream schema discovery (e.g. paginated API listings). Sources
+ without caches can ignore the flag.
+ """
raise NotImplementedError()
@property
diff --git a/posthog/temporal/data_imports/sources/convex/source.py b/posthog/temporal/data_imports/sources/convex/source.py
index 9aeb8cc50df3..2077a920ca01 100644
--- a/posthog/temporal/data_imports/sources/convex/source.py
+++ b/posthog/temporal/data_imports/sources/convex/source.py
@@ -72,6 +72,7 @@ You can find your deployment URL and deploy key in your [Convex Dashboard](https
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
clean_url = validate_deploy_url(config.deploy_url)
schemas_response = get_json_schemas(clean_url, config.deploy_key)
diff --git a/posthog/temporal/data_imports/sources/customer_io/source.py b/posthog/temporal/data_imports/sources/customer_io/source.py
index 7a54db793c05..6322de4c635a 100644
--- a/posthog/temporal/data_imports/sources/customer_io/source.py
+++ b/posthog/temporal/data_imports/sources/customer_io/source.py
@@ -186,6 +186,7 @@ class CustomerIOSource(
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
# `supports_append=False` on the webhook schemas: events arrive via the realtime
# webhook pipeline (not the polling sync), so user-facing append/full-refresh
diff --git a/posthog/temporal/data_imports/sources/doit/source.py b/posthog/temporal/data_imports/sources/doit/source.py
index 4dc9e7e0415a..15bc640c77e1 100644
--- a/posthog/temporal/data_imports/sources/doit/source.py
+++ b/posthog/temporal/data_imports/sources/doit/source.py
@@ -24,7 +24,12 @@ class DoItSource(SimpleSource[DoItSourceConfig]):
return ExternalDataSourceType.DOIT
def get_schemas(
- self, config: DoItSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: DoItSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
reports = doit_list_reports(config)
diff --git a/posthog/temporal/data_imports/sources/github/source.py b/posthog/temporal/data_imports/sources/github/source.py
index aaa9f4c22251..e01dfa9140a0 100644
--- a/posthog/temporal/data_imports/sources/github/source.py
+++ b/posthog/temporal/data_imports/sources/github/source.py
@@ -126,7 +126,12 @@ class GithubSource(ResumableSource[GithubSourceConfig, GithubResumeConfig], OAut
return integration.access_token
def get_schemas(
- self, config: GithubSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: GithubSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/google_ads/source.py b/posthog/temporal/data_imports/sources/google_ads/source.py
index b144cafd1e4e..3a24be32b277 100644
--- a/posthog/temporal/data_imports/sources/google_ads/source.py
+++ b/posthog/temporal/data_imports/sources/google_ads/source.py
@@ -65,6 +65,7 @@ class GoogleAdsSource(
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
google_ads_schemas = get_google_ads_schemas(
config,
diff --git a/posthog/temporal/data_imports/sources/google_sheets/source.py b/posthog/temporal/data_imports/sources/google_sheets/source.py
index ed87e7609bb1..1d2209d638d7 100644
--- a/posthog/temporal/data_imports/sources/google_sheets/source.py
+++ b/posthog/temporal/data_imports/sources/google_sheets/source.py
@@ -47,6 +47,7 @@ class GoogleSheetsSource(SimpleSource[GoogleSheetsSourceConfig]):
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
sheets = get_google_sheets_schemas(config)
diff --git a/posthog/temporal/data_imports/sources/hubspot/source.py b/posthog/temporal/data_imports/sources/hubspot/source.py
index ecd1d379df5e..359eabf46c01 100644
--- a/posthog/temporal/data_imports/sources/hubspot/source.py
+++ b/posthog/temporal/data_imports/sources/hubspot/source.py
@@ -100,6 +100,7 @@ class HubspotSource(ResumableSource[HubspotSourceConfig | HubspotSourceOldConfig
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
for endpoint in HUBSPOT_ENDPOINTS:
diff --git a/posthog/temporal/data_imports/sources/klaviyo/source.py b/posthog/temporal/data_imports/sources/klaviyo/source.py
index 3bfbc37ff02d..1f5821bebc42 100644
--- a/posthog/temporal/data_imports/sources/klaviyo/source.py
+++ b/posthog/temporal/data_imports/sources/klaviyo/source.py
@@ -66,7 +66,12 @@ Make sure to grant the following read permissions:
)
def get_schemas(
- self, config: KlaviyoSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: KlaviyoSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
# Events are immutable - append-only is the only sync mode
append_only_endpoints = {"events"}
diff --git a/posthog/temporal/data_imports/sources/linear/source.py b/posthog/temporal/data_imports/sources/linear/source.py
index 326c9811013a..5d9b4cd7640a 100644
--- a/posthog/temporal/data_imports/sources/linear/source.py
+++ b/posthog/temporal/data_imports/sources/linear/source.py
@@ -69,7 +69,12 @@ class LinearSource(ResumableSource[LinearSourceConfig, LinearResumeConfig], OAut
return integration.access_token
def get_schemas(
- self, config: LinearSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: LinearSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/linkedin_ads/source.py b/posthog/temporal/data_imports/sources/linkedin_ads/source.py
index 13c2cd18e91f..0fdbe5430dcb 100644
--- a/posthog/temporal/data_imports/sources/linkedin_ads/source.py
+++ b/posthog/temporal/data_imports/sources/linkedin_ads/source.py
@@ -105,6 +105,7 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
linkedin_ads_schemas = get_linkedin_ads_schemas()
ads_incremental_fields = get_linkedin_ads_incremental_fields()
diff --git a/posthog/temporal/data_imports/sources/mailchimp/source.py b/posthog/temporal/data_imports/sources/mailchimp/source.py
index 3983713a63b2..46d9433aae71 100644
--- a/posthog/temporal/data_imports/sources/mailchimp/source.py
+++ b/posthog/temporal/data_imports/sources/mailchimp/source.py
@@ -66,7 +66,12 @@ The API key format is: `key-dc` (e.g., `abc123def456-us6`), where `dc` is the da
}
def get_schemas(
- self, config: MailchimpSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: MailchimpSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/meta_ads/source.py b/posthog/temporal/data_imports/sources/meta_ads/source.py
index f9141d5259de..80a4ba4d0ee3 100644
--- a/posthog/temporal/data_imports/sources/meta_ads/source.py
+++ b/posthog/temporal/data_imports/sources/meta_ads/source.py
@@ -39,7 +39,12 @@ class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig]):
}
def get_schemas(
- self, config: MetaAdsSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: MetaAdsSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/mongodb/source.py b/posthog/temporal/data_imports/sources/mongodb/source.py
index 19f93450ff64..d68a3ea2df90 100644
--- a/posthog/temporal/data_imports/sources/mongodb/source.py
+++ b/posthog/temporal/data_imports/sources/mongodb/source.py
@@ -37,7 +37,12 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
return {"The DNS query name does not exist": None, "authentication failed": None, "SSL handshake failed": None}
def get_schemas(
- self, config: MongoDBSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: MongoDBSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
mongo_schemas = get_mongo_schemas(config, team_id=team_id, names=names)
diff --git a/posthog/temporal/data_imports/sources/mssql/source.py b/posthog/temporal/data_imports/sources/mssql/source.py
index 865f6b2eae09..c040452f87ee 100644
--- a/posthog/temporal/data_imports/sources/mssql/source.py
+++ b/posthog/temporal/data_imports/sources/mssql/source.py
@@ -126,7 +126,12 @@ class MSSQLSource(SimpleSource[MSSQLSourceConfig], SSHTunnelMixin, ValidateDatab
)
def get_schemas(
- self, config: MSSQLSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: MSSQLSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
diff --git a/posthog/temporal/data_imports/sources/mysql/source.py b/posthog/temporal/data_imports/sources/mysql/source.py
index 3438103aa8b0..8040f1e9f255 100644
--- a/posthog/temporal/data_imports/sources/mysql/source.py
+++ b/posthog/temporal/data_imports/sources/mysql/source.py
@@ -137,7 +137,12 @@ class MySQLSource(SimpleSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatab
}
def get_schemas(
- self, config: MySQLSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: MySQLSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
diff --git a/posthog/temporal/data_imports/sources/paddle/source.py b/posthog/temporal/data_imports/sources/paddle/source.py
index a835cdee3495..5cc1db4a101b 100644
--- a/posthog/temporal/data_imports/sources/paddle/source.py
+++ b/posthog/temporal/data_imports/sources/paddle/source.py
@@ -78,7 +78,12 @@ class PaddleSource(ResumableSource[PaddleSourceConfig, PaddleResumeConfig]):
return False, str(e)
def get_schemas(
- self, config: PaddleSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: PaddleSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/pinterest_ads/source.py b/posthog/temporal/data_imports/sources/pinterest_ads/source.py
index ff10a95c1636..7dbf0a73daa8 100644
--- a/posthog/temporal/data_imports/sources/pinterest_ads/source.py
+++ b/posthog/temporal/data_imports/sources/pinterest_ads/source.py
@@ -103,6 +103,7 @@ class PinterestAdsSource(ResumableSource[PinterestAdsSourceConfig, PinterestAdsR
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/plain/source.py b/posthog/temporal/data_imports/sources/plain/source.py
index df3452fdb522..f40148be134d 100644
--- a/posthog/temporal/data_imports/sources/plain/source.py
+++ b/posthog/temporal/data_imports/sources/plain/source.py
@@ -67,7 +67,12 @@ Make sure to grant the following read permissions:
}
def get_schemas(
- self, config: PlainSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: PlainSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.py
index 0933b8250e4d..d11d180dfe40 100644
--- a/posthog/temporal/data_imports/sources/postgres/source.py
+++ b/posthog/temporal/data_imports/sources/postgres/source.py
@@ -211,7 +211,12 @@ class PostgresSource(SimpleSource[PostgresSourceConfig], SSHTunnelMixin, Validat
)
def get_schemas(
- self, config: PostgresSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: PostgresSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
diff --git a/posthog/temporal/data_imports/sources/reddit_ads/source.py b/posthog/temporal/data_imports/sources/reddit_ads/source.py
index 10cd35506b02..6db7907c3690 100644
--- a/posthog/temporal/data_imports/sources/reddit_ads/source.py
+++ b/posthog/temporal/data_imports/sources/reddit_ads/source.py
@@ -90,7 +90,12 @@ class RedditAdsSource(ResumableSource[RedditAdsSourceConfig, RedditAdsResumeConf
return False, f"Failed to validate Reddit Ads credentials: {str(e)}"
def get_schemas(
- self, config: RedditAdsSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: RedditAdsSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/redshift/source.py b/posthog/temporal/data_imports/sources/redshift/source.py
index 02716641a279..6f8690ce2cf8 100644
--- a/posthog/temporal/data_imports/sources/redshift/source.py
+++ b/posthog/temporal/data_imports/sources/redshift/source.py
@@ -146,7 +146,12 @@ class RedshiftSource(SimpleSource[RedshiftSourceConfig], SSHTunnelMixin, Validat
}
def get_schemas(
- self, config: RedshiftSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: RedshiftSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
diff --git a/posthog/temporal/data_imports/sources/resend/source.py b/posthog/temporal/data_imports/sources/resend/source.py
index 40ac6dfd3e23..042faff3ce40 100644
--- a/posthog/temporal/data_imports/sources/resend/source.py
+++ b/posthog/temporal/data_imports/sources/resend/source.py
@@ -65,7 +65,12 @@ Grant the key **full access** or a read-enabled access token so the following re
)
def get_schemas(
- self, config: ResendSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: ResendSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
# Resend's API does not expose server-side filters on created_at; sync as
# full-refresh only. Within-sync resumption is handled by ResumableSource.
diff --git a/posthog/temporal/data_imports/sources/salesforce/source.py b/posthog/temporal/data_imports/sources/salesforce/source.py
index 649ebbbfd5de..e688c1493167 100644
--- a/posthog/temporal/data_imports/sources/salesforce/source.py
+++ b/posthog/temporal/data_imports/sources/salesforce/source.py
@@ -35,7 +35,12 @@ class SalesforceSource(ResumableSource[SalesforceSourceConfig, SalesforceResumeC
}
def get_schemas(
- self, config: SalesforceSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: SalesforceSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/sentry/source.py b/posthog/temporal/data_imports/sources/sentry/source.py
index de7e51b0fcfe..554c7b98ab03 100644
--- a/posthog/temporal/data_imports/sources/sentry/source.py
+++ b/posthog/temporal/data_imports/sources/sentry/source.py
@@ -98,7 +98,12 @@ Create a token in Sentry and make sure it includes the scopes below if you want
}
def get_schemas(
- self, config: SentrySourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: SentrySourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas: list[SourceSchema] = []
for endpoint in ENDPOINTS:
diff --git a/posthog/temporal/data_imports/sources/shopify/source.py b/posthog/temporal/data_imports/sources/shopify/source.py
index fc8dca6e7722..1e7818145be5 100644
--- a/posthog/temporal/data_imports/sources/shopify/source.py
+++ b/posthog/temporal/data_imports/sources/shopify/source.py
@@ -86,7 +86,12 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):
return False, str(e)
def get_schemas(
- self, config: ShopifySourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: ShopifySourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
for obj in SHOPIFY_GRAPHQL_OBJECTS.values():
diff --git a/posthog/temporal/data_imports/sources/slack/slack.py b/posthog/temporal/data_imports/sources/slack/slack.py
index 79bc9bb004d1..a7b06877ca9f 100644
--- a/posthog/temporal/data_imports/sources/slack/slack.py
+++ b/posthog/temporal/data_imports/sources/slack/slack.py
@@ -3,6 +3,8 @@ import dataclasses
from collections.abc import AsyncIterable, Callable, Iterable, Iterator
from typing import Any, Optional
+from django.core.cache import cache
+
import orjson
import pyarrow as pa
import requests
@@ -173,6 +175,41 @@ def _fetch_all_channels(access_token: str, authed_user: str | None = None) -> li
return public + private
+_CHANNELS_CACHE_TTL_SECONDS = 300
+
+
+def _channels_cache_key(integration_id: int) -> str:
+ # Keyed on the Integration row PK (unique per PostHog team × Slack workspace), matching
+ # the convention used by the HogFunctions Slack channel-list cache in posthog.api.integration.
+ return f"@dwh/slack/{integration_id}/channels"
+
+
+def _fetch_all_channels_cached(
+ integration_id: int,
+ access_token: str,
+ authed_user: str | None = None,
+ force_refresh: bool = False,
+) -> list[dict[str, Any]]:
+ """Cached wrapper around `_fetch_all_channels`.
+
+ Slack's `conversations.list` is Tier 2 (~20 req/min). Workspaces with thousands of
+ channels exhaust that budget in a single discovery pass, so callers that don't
+ strictly need fresh data should go through this wrapper. Callers that need fresh
+ data (e.g. the user-triggered `refresh_schemas` action) should pass
+ ``force_refresh=True`` — the upstream call still happens, but the previous value
+ stays in cache until the new one is written, so concurrent readers don't pile up
+ on a missing key.
+ """
+ cache_key = _channels_cache_key(integration_id)
+ if not force_refresh:
+ cached = cache.get(cache_key)
+ if cached is not None:
+ return cached
+ channels = _fetch_all_channels(access_token, authed_user)
+ cache.set(cache_key, channels, _CHANNELS_CACHE_TTL_SECONDS)
+ return channels
+
+
def _fetch_messages_page(
access_token: str,
channel_id: str,
@@ -250,9 +287,17 @@ def _fetch_thread_replies(
has_more = cursor is not None
-def get_channels(access_token: str, authed_user: str | None = None) -> list[dict[str, str]]:
+def get_channels(
+ integration_id: int,
+ access_token: str,
+ authed_user: str | None = None,
+ force_refresh: bool = False,
+) -> list[dict[str, str]]:
"""Return channel id + name pairs for all accessible channels."""
- return [{"id": ch["id"], "name": ch["name"]} for ch in _fetch_all_channels(access_token, authed_user)]
+ return [
+ {"id": ch["id"], "name": ch["name"]}
+ for ch in _fetch_all_channels_cached(integration_id, access_token, authed_user, force_refresh=force_refresh)
+ ]
def _add_timestamp(msg: dict[str, Any]) -> dict[str, Any]:
@@ -337,6 +382,7 @@ def _webhook_table_transformer(table: pa.Table) -> pa.Table:
def slack_source(
access_token: str,
+ integration_id: int,
endpoint: str,
team_id: int,
job_id: str,
@@ -356,7 +402,7 @@ def slack_source(
# public+private types are mixed, so we walk public and private separately and
# scope private channels to the installer (matches get_schemas behavior).
endpoint_config = ENDPOINTS[endpoint]
- items = lambda: iter(_fetch_all_channels(access_token, authed_user))
+ items = lambda: iter(_fetch_all_channels_cached(integration_id, access_token, authed_user))
elif endpoint in ENDPOINTS:
# $users — served via the generic REST framework
endpoint_config = ENDPOINTS[endpoint]
diff --git a/posthog/temporal/data_imports/sources/slack/source.py b/posthog/temporal/data_imports/sources/slack/source.py
index b89f75356549..1d55b6533079 100644
--- a/posthog/temporal/data_imports/sources/slack/source.py
+++ b/posthog/temporal/data_imports/sources/slack/source.py
@@ -165,7 +165,12 @@ class SlackSource(ResumableSource[SlackSourceConfig, SlackResumeConfig], Webhook
}
def get_schemas(
- self, config: SlackSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: SlackSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas: list[SourceSchema] = [
SourceSchema(
@@ -185,7 +190,7 @@ class SlackSource(ResumableSource[SlackSourceConfig, SlackResumeConfig], Webhook
msg_config = messages_endpoint_config()
webhook_flag_enabled = is_webhook_feature_flag_enabled(team_id)
authed_user = self._get_authed_user_id(integration)
- channels = get_channels(access_token, authed_user)
+ channels = get_channels(integration.id, access_token, authed_user, force_refresh=force_refresh)
for ch in channels:
if ch["id"] in ENDPOINTS:
continue
@@ -241,6 +246,7 @@ class SlackSource(ResumableSource[SlackSourceConfig, SlackResumeConfig], Webhook
return slack_source(
access_token=access_token,
+ integration_id=integration.id,
endpoint=inputs.schema_name,
team_id=inputs.team_id,
job_id=inputs.job_id,
diff --git a/posthog/temporal/data_imports/sources/slack/test_slack.py b/posthog/temporal/data_imports/sources/slack/test_slack.py
index 51353e43fc12..d5f04041df74 100644
--- a/posthog/temporal/data_imports/sources/slack/test_slack.py
+++ b/posthog/temporal/data_imports/sources/slack/test_slack.py
@@ -2,14 +2,18 @@ from typing import Any
from unittest.mock import MagicMock, patch
+from django.core.cache import cache as django_cache
+
from parameterized import parameterized
from posthog.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from posthog.temporal.data_imports.sources.common.webhook_s3 import WebhookSourceManager
+from posthog.temporal.data_imports.sources.slack.settings import ENDPOINTS
from posthog.temporal.data_imports.sources.slack.slack import (
SlackResumeConfig,
_channel_messages_generator,
_fetch_all_channels,
+ _fetch_all_channels_cached,
_fetch_channels_by_type,
slack_source,
)
@@ -262,10 +266,145 @@ class TestFetchAllChannels:
assert mock_get.call_args_list[1].kwargs["params"]["user"] == "U_INSTALLER"
+class TestFetchAllChannelsCached:
+ def setup_method(self) -> None:
+ django_cache.clear()
+
+ def teardown_method(self) -> None:
+ django_cache.clear()
+
+ def test_second_call_uses_cache(self) -> None:
+ with patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ return_value=[{"id": "C1", "name": "general"}],
+ ) as mock_fetch:
+ first = _fetch_all_channels_cached(integration_id=42, access_token="token", authed_user="U_INSTALLER")
+ second = _fetch_all_channels_cached(integration_id=42, access_token="token", authed_user="U_INSTALLER")
+
+ assert first == second == [{"id": "C1", "name": "general"}]
+ assert mock_fetch.call_count == 1
+
+ def test_different_integrations_get_independent_cache_entries(self) -> None:
+ with patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ side_effect=[[{"id": "A1", "name": "a"}], [{"id": "B1", "name": "b"}]],
+ ) as mock_fetch:
+ a = _fetch_all_channels_cached(integration_id=1, access_token="token", authed_user="U1")
+ b = _fetch_all_channels_cached(integration_id=2, access_token="token", authed_user="U1")
+
+ assert a == [{"id": "A1", "name": "a"}]
+ assert b == [{"id": "B1", "name": "b"}]
+ assert mock_fetch.call_count == 2
+
+ def test_force_refresh_refetches_and_overwrites_cache(self) -> None:
+ with patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ side_effect=[[{"id": "C1", "name": "general"}], [{"id": "C2", "name": "renamed"}]],
+ ) as mock_fetch:
+ first = _fetch_all_channels_cached(integration_id=42, access_token="token", authed_user="U_INSTALLER")
+ second = _fetch_all_channels_cached(
+ integration_id=42, access_token="token", authed_user="U_INSTALLER", force_refresh=True
+ )
+ third = _fetch_all_channels_cached(integration_id=42, access_token="token", authed_user="U_INSTALLER")
+
+ assert first == [{"id": "C1", "name": "general"}]
+ assert second == [{"id": "C2", "name": "renamed"}]
+ # Third call hits the cache populated by the force_refresh write.
+ assert third == [{"id": "C2", "name": "renamed"}]
+ assert mock_fetch.call_count == 2
+
+ def test_force_refresh_does_not_evict_on_failure(self) -> None:
+ # If the upstream fetch raises, the previous cached value must remain so
+ # concurrent readers continue to see stale-but-valid data.
+ with patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ return_value=[{"id": "C1", "name": "general"}],
+ ):
+ _fetch_all_channels_cached(integration_id=42, access_token="token", authed_user="U_INSTALLER")
+
+ with patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ side_effect=RuntimeError("rate limited"),
+ ):
+ try:
+ _fetch_all_channels_cached(
+ integration_id=42, access_token="token", authed_user="U_INSTALLER", force_refresh=True
+ )
+ except RuntimeError:
+ pass
+
+ with patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ return_value=[{"id": "WRONG", "name": "should_not_be_called"}],
+ ) as mock_fetch:
+ after = _fetch_all_channels_cached(integration_id=42, access_token="token", authed_user="U_INSTALLER")
+
+ assert after == [{"id": "C1", "name": "general"}]
+ assert mock_fetch.call_count == 0
+
+
+class TestSlackSourceGetSchemasForceRefresh:
+ def setup_method(self) -> None:
+ django_cache.clear()
+
+ def teardown_method(self) -> None:
+ django_cache.clear()
+
+ def _build_mocks(self) -> tuple[Any, Any]:
+ config = MagicMock()
+ config.slack_integration_id = 42
+
+ integration = MagicMock()
+ integration.id = 42
+ integration.access_token = "token"
+ integration.config = {"authed_user": {"id": "U_INSTALLER"}}
+
+ return config, integration
+
+ def test_force_refresh_bypasses_channels_cache(self) -> None:
+ from posthog.temporal.data_imports.sources.slack.source import SlackSource
+
+ config, integration = self._build_mocks()
+ source = SlackSource()
+
+ with (
+ patch.object(source, "get_oauth_integration", return_value=integration),
+ patch(
+ "posthog.temporal.data_imports.sources.slack.slack._fetch_all_channels",
+ side_effect=[[{"id": "C1", "name": "general"}], [{"id": "C2", "name": "renamed"}]],
+ ) as mock_fetch,
+ patch(
+ "posthog.temporal.data_imports.sources.slack.source.is_webhook_feature_flag_enabled",
+ return_value=False,
+ ),
+ ):
+ first = source.get_schemas(config, team_id=1)
+ cached = source.get_schemas(config, team_id=1)
+ forced = source.get_schemas(config, team_id=1, force_refresh=True)
+
+ # Two upstream fetches total: the first cold call and the force_refresh call.
+ # The middle call must be a cache hit.
+ assert mock_fetch.call_count == 2
+
+ def channel_names(schemas: Any) -> set[str]:
+ return {s.name for s in schemas if s.name not in ENDPOINTS}
+
+ assert channel_names(first) == {"C1"}
+ assert channel_names(cached) == {"C1"}
+ assert channel_names(forced) == {"C2"}
+
+
class TestSlackSourceChannelsEndpoint:
+ def setup_method(self) -> None:
+ django_cache.clear()
+
+ def teardown_method(self) -> None:
+ django_cache.clear()
+
def _build_source(self, authed_user: str | None) -> Any:
return slack_source(
access_token="token",
+ integration_id=42,
endpoint="$channels",
team_id=1,
job_id="job-1",
diff --git a/posthog/temporal/data_imports/sources/snapchat_ads/source.py b/posthog/temporal/data_imports/sources/snapchat_ads/source.py
index 8c12d0d06356..b66597af0d95 100644
--- a/posthog/temporal/data_imports/sources/snapchat_ads/source.py
+++ b/posthog/temporal/data_imports/sources/snapchat_ads/source.py
@@ -92,6 +92,7 @@ class SnapchatAdsSource(ResumableSource[SnapchatAdsSourceConfig, SnapchatResumeC
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/snowflake/source.py b/posthog/temporal/data_imports/sources/snowflake/source.py
index 41e6668bf1b2..4e715d10a6c7 100644
--- a/posthog/temporal/data_imports/sources/snowflake/source.py
+++ b/posthog/temporal/data_imports/sources/snowflake/source.py
@@ -184,7 +184,12 @@ class SnowflakeSource(SimpleSource[SnowflakeSourceConfig]):
}
def get_schemas(
- self, config: SnowflakeSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: SnowflakeSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = []
diff --git a/posthog/temporal/data_imports/sources/source.template b/posthog/temporal/data_imports/sources/source.template
index baf41ce3c456..36fada33b028 100644
--- a/posthog/temporal/data_imports/sources/source.template
+++ b/posthog/temporal/data_imports/sources/source.template
@@ -73,7 +73,7 @@ class TemplateSource(SimpleSource[Config]): # rename this class and replace `Co
) # implement logic to validate the credentials of your source, e.g. check the validity of API keys. return a tuple of whether the credentials are valid, and if not, return an error message to return to the user
def get_schemas(
- self, config: Config, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self, config: Config, team_id: int, with_counts: bool = False, names: list[str] | None = None, force_refresh: bool = False
) -> list[SourceSchema]: # replace `Config` with the generated class
return [] # implement your source logic
diff --git a/posthog/temporal/data_imports/sources/stripe/source.py b/posthog/temporal/data_imports/sources/stripe/source.py
index a17d62834096..3a6752a80e0b 100644
--- a/posthog/temporal/data_imports/sources/stripe/source.py
+++ b/posthog/temporal/data_imports/sources/stripe/source.py
@@ -267,6 +267,7 @@ If automatic creation failed due to a permissions error and you're using a restr
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/temporalio/source.py b/posthog/temporal/data_imports/sources/temporalio/source.py
index 3d26f05e2179..64ae01ba6256 100644
--- a/posthog/temporal/data_imports/sources/temporalio/source.py
+++ b/posthog/temporal/data_imports/sources/temporalio/source.py
@@ -31,7 +31,12 @@ class TemporalIOSource(ResumableSource[TemporalIOSourceConfig, TemporalIOResumeC
return ExternalDataSourceType.TEMPORALIO
def get_schemas(
- self, config: TemporalIOSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: TemporalIOSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/tiktok_ads/source.py b/posthog/temporal/data_imports/sources/tiktok_ads/source.py
index e4afdc528aaa..1dcb1e024558 100644
--- a/posthog/temporal/data_imports/sources/tiktok_ads/source.py
+++ b/posthog/temporal/data_imports/sources/tiktok_ads/source.py
@@ -87,7 +87,12 @@ class TikTokAdsSource(ResumableSource[TikTokAdsSourceConfig, TikTokAdsResumeConf
return False, f"Failed to validate TikTok Ads credentials: {str(e)}"
def get_schemas(
- self, config: TikTokAdsSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: TikTokAdsSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/typeform/source.py b/posthog/temporal/data_imports/sources/typeform/source.py
index 614b15026915..3a47fad5a9cf 100644
--- a/posthog/temporal/data_imports/sources/typeform/source.py
+++ b/posthog/temporal/data_imports/sources/typeform/source.py
@@ -92,7 +92,12 @@ You can generate a personal access token in your [Typeform account settings](htt
}
def get_schemas(
- self, config: TypeformSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: TypeformSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas: list[SourceSchema] = []
for endpoint in ENDPOINTS:
diff --git a/posthog/temporal/data_imports/sources/vitally/source.py b/posthog/temporal/data_imports/sources/vitally/source.py
index f351fb47626d..3f9d84d9f46e 100644
--- a/posthog/temporal/data_imports/sources/vitally/source.py
+++ b/posthog/temporal/data_imports/sources/vitally/source.py
@@ -34,7 +34,12 @@ class VitallySource(SimpleSource[VitallySourceConfig]):
return ExternalDataSourceType.VITALLY
def get_schemas(
- self, config: VitallySourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: VitallySourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/posthog/temporal/data_imports/sources/zendesk/source.py b/posthog/temporal/data_imports/sources/zendesk/source.py
index 37a076e8b00d..e4c8807e0370 100644
--- a/posthog/temporal/data_imports/sources/zendesk/source.py
+++ b/posthog/temporal/data_imports/sources/zendesk/source.py
@@ -38,7 +38,12 @@ class ZendeskSource(SimpleSource[ZendeskSourceConfig]):
}
def get_schemas(
- self, config: ZendeskSourceConfig, team_id: int, with_counts: bool = False, names: list[str] | None = None
+ self,
+ config: ZendeskSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
diff --git a/products/data_warehouse/backend/api/external_data_source.py b/products/data_warehouse/backend/api/external_data_source.py
index ba2701d633eb..93e29533c167 100644
--- a/products/data_warehouse/backend/api/external_data_source.py
+++ b/products/data_warehouse/backend/api/external_data_source.py
@@ -1423,7 +1423,9 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
source_type = ExternalDataSourceType(instance.source_type)
source = SourceRegistry.get_source(source_type)
config = source.parse_config(instance.job_inputs)
- schemas = source.get_schemas(config, self.team_id)
+ # Explicit user action — bypass any cached schema discovery so newly added
+ # upstream resources (e.g. Slack channels) appear immediately.
+ schemas = source.get_schemas(config, self.team_id, force_refresh=True)
connection_metadata = (
get_direct_postgres_connection_metadata(
source_impl=source,