: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(replay): cache expiring-soon synthetic playlist scan (#63884)
Paul D'Ambra376e5ef57445
diff --git a/posthog/session_recordings/synthetic_playlists.py b/posthog/session_recordings/synthetic_playlists.pyindex e4f92678a751..f683f65e7832 100644--- a/posthog/session_recordings/synthetic_playlists.py+++ b/posthog/session_recordings/synthetic_playlists.py@@ -233,25 +233,45 @@ class SummarisedPlaylistSource(SyntheticPlaylistSource):@dataclassclass ExpiringPlaylistSource(SyntheticPlaylistSource):- def get_session_ids(self, team: Team, user: User, limit: int | None = None, offset: int | None = None) -> list[str]:- fetch_limit = ((offset or 0) + (limit or 50)) * 2- query = RecordingsQuery(limit=fetch_limit, order=RecordingOrder.RECORDING_TTL)- recordings, _, _, _ = list_recordings_from_query(query, user, team)+ """+ Surfaces recordings whose retention window ends within the next 10 days.+ The expiry window is computed in Python over a ClickHouse scan ordered by TTL,+ so the filtered session ids are cached for 1 hour and shared by the count and+ pagination paths to avoid re-scanning on every list load.+ """- now = datetime.now(UTC)- ten_days_from_now = now + timedelta(days=10)+ CACHE_KEY_PREFIX = "expiring_synthetic_playlist"+ CACHE_TTL = 3600 # 1 hour+ EXPIRY_WINDOW_DAYS = 10+ SCAN_LIMIT = 10000- result = [r.session_id for r in recordings if r.expiry_time and now <= r.expiry_time <= ten_days_from_now]- return self._paginate_list(result, limit, offset)+ @staticmethod+ def _get_cache_key(team_id: int) -> str:+ return f"{ExpiringPlaylistSource.CACHE_KEY_PREFIX}_team_{team_id}"- def count_session_ids(self, team: Team, user: User) -> int:- query = RecordingsQuery(limit=10000, order=RecordingOrder.RECORDING_TTL)+ @staticmethod+ def _get_expiring_session_ids(team: Team, user: User) -> list[str]:+ cache_key = ExpiringPlaylistSource._get_cache_key(team.pk)+ cached_data = cache.get(cache_key)+ if cached_data is not None:+ return cached_data++ query = RecordingsQuery(limit=ExpiringPlaylistSource.SCAN_LIMIT, order=RecordingOrder.RECORDING_TTL)recordings, _, _, _ = list_recordings_from_query(query, user, team)now = datetime.now(UTC)- ten_days_from_now = now + timedelta(days=10)+ window_end = now + timedelta(days=ExpiringPlaylistSource.EXPIRY_WINDOW_DAYS)++ session_ids = [r.session_id for r in recordings if r.expiry_time and now <= r.expiry_time <= window_end]+ cache.set(cache_key, session_ids, ExpiringPlaylistSource.CACHE_TTL)+ return session_ids- return sum(1 for r in recordings if r.expiry_time and now <= r.expiry_time <= ten_days_from_now)+ def get_session_ids(self, team: Team, user: User, limit: int | None = None, offset: int | None = None) -> list[str]:+ session_ids = self._get_expiring_session_ids(team, user)+ return self._paginate_list(session_ids, limit, offset)++ def count_session_ids(self, team: Team, user: User) -> int:+ return len(self._get_expiring_session_ids(team, user))def to_synthetic_playlist(self) -> "SyntheticPlaylistDefinition":return SyntheticPlaylistDefinition(diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambrindex e6f0896073c5..d745aed54da2 100644--- a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr+++ b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr@@ -1000,113 +1000,14 @@# ---# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.28'''- SELECT "posthog_datawarehousesavedquery"."created_by_id",- "posthog_datawarehousesavedquery"."created_at",- "posthog_datawarehousesavedquery"."updated_at",- "posthog_datawarehousesavedquery"."deleted",- "posthog_datawarehousesavedquery"."deleted_at",- "posthog_datawarehousesavedquery"."id",- "posthog_datawarehousesavedquery"."name",- "posthog_datawarehousesavedquery"."team_id",- "posthog_datawarehousesavedquery"."latest_error",- "posthog_datawarehousesavedquery"."columns",- "posthog_datawarehousesavedquery"."external_tables",- "posthog_datawarehousesavedquery"."query",- "posthog_datawarehousesavedquery"."status",- "posthog_datawarehousesavedquery"."last_run_at",- "posthog_datawarehousesavedquery"."sync_frequency_interval",- "posthog_datawarehousesavedquery"."table_id",- "posthog_datawarehousesavedquery"."is_materialized",- "posthog_datawarehousesavedquery"."deleted_name",- "posthog_datawarehousesavedquery"."managed_viewset_id",- "posthog_datawarehousesavedquery"."folder_id",- "posthog_datawarehousesavedquery"."origin",- "posthog_datawarehousesavedquery"."is_test",- "posthog_datawarehousesavedquery"."expires_at",- "posthog_datawarehousetable"."created_by_id",- "posthog_datawarehousetable"."created_at",- "posthog_datawarehousetable"."updated_at",- "posthog_datawarehousetable"."deleted",- "posthog_datawarehousetable"."deleted_at",- "posthog_datawarehousetable"."id",- "posthog_datawarehousetable"."name",- "posthog_datawarehousetable"."format",- "posthog_datawarehousetable"."team_id",- "posthog_datawarehousetable"."url_pattern",- "posthog_datawarehousetable"."queryable_folder",- "posthog_datawarehousetable"."credential_id",- "posthog_datawarehousetable"."external_data_source_id",- "posthog_datawarehousetable"."columns",- "posthog_datawarehousetable"."options",- "posthog_datawarehousetable"."row_count",- "posthog_datawarehousetable"."size_in_s3_mib",- "posthog_datawarehousemanagedviewset"."created_by_id",- "posthog_datawarehousemanagedviewset"."created_at",- "posthog_datawarehousemanagedviewset"."updated_at",- "posthog_datawarehousemanagedviewset"."id",- "posthog_datawarehousemanagedviewset"."team_id",- "posthog_datawarehousemanagedviewset"."kind"- FROM "posthog_datawarehousesavedquery"- LEFT OUTER JOIN "posthog_datawarehousemanagedviewset" ON ("posthog_datawarehousesavedquery"."managed_viewset_id" = "posthog_datawarehousemanagedviewset"."id")- LEFT OUTER JOIN "posthog_datawarehousetable" ON ("posthog_datawarehousesavedquery"."table_id" = "posthog_datawarehousetable"."id")- WHERE ("posthog_datawarehousesavedquery"."team_id" = 99999- AND NOT ("posthog_datawarehousesavedquery"."deleted"- AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)- AND "posthog_datawarehousesavedquery"."managed_viewset_id" IS NULL)- ORDER BY "posthog_datawarehousesavedquery"."name" ASC+ SELECT COUNT(*)+ FROM+ (SELECT DISTINCT "ee_single_session_summary"."session_id" AS "session_id"+ FROM "ee_single_session_summary"+ WHERE "ee_single_session_summary"."team_id" = 99999) subquery'''# ---# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.29- '''- SELECT "posthog_datawarehousesavedquery"."created_by_id",- "posthog_datawarehousesavedquery"."created_at",- "posthog_datawarehousesavedquery"."updated_at",- "posthog_datawarehousesavedquery"."deleted",- "posthog_datawarehousesavedquery"."deleted_at",- "posthog_datawarehousesavedquery"."id",- "posthog_datawarehousesavedquery"."name",- "posthog_datawarehousesavedquery"."team_id",- "posthog_datawarehousesavedquery"."latest_error",- "posthog_datawarehousesavedquery"."columns",- "posthog_datawarehousesavedquery"."external_tables",- "posthog_datawarehousesavedquery"."query",- "posthog_datawarehousesavedquery"."status",- "posthog_datawarehousesavedquery"."last_run_at",- "posthog_datawarehousesavedquery"."sync_frequency_interval",- "posthog_datawarehousesavedquery"."table_id",- "posthog_datawarehousesavedquery"."is_materialized",- "posthog_datawarehousesavedquery"."deleted_name",- "posthog_datawarehousesavedquery"."managed_viewset_id",- "posthog_datawarehousesavedquery"."folder_id",- "posthog_datawarehousesavedquery"."origin",- "posthog_datawarehousesavedquery"."is_test",- "posthog_datawarehousesavedquery"."expires_at",- "posthog_datawarehousetable"."created_by_id",- "posthog_datawarehousetable"."created_at",- "posthog_datawarehousetable"."updated_at",- "posthog_datawarehousetable"."deleted",- "posthog_datawarehousetable"."deleted_at",- "posthog_datawarehousetable"."id",- "posthog_datawarehousetable"."name",- "posthog_datawarehousetable"."format",- "posthog_datawarehousetable"."team_id",- "posthog_datawarehousetable"."url_pattern",- "posthog_datawarehousetable"."queryable_folder",- "posthog_datawarehousetable"."credential_id",- "posthog_datawarehousetable"."external_data_source_id",- "posthog_datawarehousetable"."columns",- "posthog_datawarehousetable"."options",- "posthog_datawarehousetable"."row_count",- "posthog_datawarehousetable"."size_in_s3_mib"- FROM "posthog_datawarehousesavedquery"- LEFT OUTER JOIN "posthog_datawarehousetable" ON ("posthog_datawarehousesavedquery"."table_id" = "posthog_datawarehousetable"."id")- WHERE ("posthog_datawarehousesavedquery"."team_id" = 99999- AND "posthog_datawarehousesavedquery"."origin" = 'endpoint'- AND NOT ("posthog_datawarehousesavedquery"."deleted"- AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL))- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.3'''SELECT "posthog_user"."id","posthog_user"."password",@@ -1151,239 +1052,7 @@AND "posthog_user"."id" = 99999)'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.30- '''- SELECT "posthog_externaldatasource"."created_by_id",- "posthog_externaldatasource"."created_at",- "posthog_externaldatasource"."updated_at",- "posthog_externaldatasource"."deleted",- "posthog_externaldatasource"."deleted_at",- "posthog_externaldatasource"."id",- "posthog_externaldatasource"."source_id",- "posthog_externaldatasource"."connection_id",- "posthog_externaldatasource"."destination_id",- "posthog_externaldatasource"."team_id",- "posthog_externaldatasource"."sync_frequency",- "posthog_externaldatasource"."status",- "posthog_externaldatasource"."source_type",- "posthog_externaldatasource"."job_inputs",- "posthog_externaldatasource"."connection_metadata",- "posthog_externaldatasource"."are_tables_created",- "posthog_externaldatasource"."prefix",- "posthog_externaldatasource"."description",- "posthog_externaldatasource"."created_via",- "posthog_externaldatasource"."access_method",- "posthog_externaldatasource"."revenue_analytics_enabled",- "posthog_externaldatasourcerevenueanalyticsconfig"."external_data_source_id",- "posthog_externaldatasourcerevenueanalyticsconfig"."enabled",- "posthog_externaldatasourcerevenueanalyticsconfig"."include_invoiceless_charges"- FROM "posthog_externaldatasource"- LEFT OUTER JOIN "posthog_externaldatasourcerevenueanalyticsconfig" ON ("posthog_externaldatasource"."id" = "posthog_externaldatasourcerevenueanalyticsconfig"."external_data_source_id")- WHERE ("posthog_externaldatasource"."source_type" IN ('Stripe')- AND "posthog_externaldatasource"."team_id" = 99999- AND NOT ("posthog_externaldatasource"."deleted"- AND "posthog_externaldatasource"."deleted" IS NOT NULL))- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.31- '''- SELECT "posthog_datawarehousetable"."created_by_id",- "posthog_datawarehousetable"."created_at",- "posthog_datawarehousetable"."updated_at",- "posthog_datawarehousetable"."deleted",- "posthog_datawarehousetable"."deleted_at",- "posthog_datawarehousetable"."id",- "posthog_datawarehousetable"."name",- "posthog_datawarehousetable"."format",- "posthog_datawarehousetable"."team_id",- "posthog_datawarehousetable"."url_pattern",- "posthog_datawarehousetable"."queryable_folder",- "posthog_datawarehousetable"."credential_id",- "posthog_datawarehousetable"."external_data_source_id",- "posthog_datawarehousetable"."columns",- "posthog_datawarehousetable"."options",- "posthog_datawarehousetable"."row_count",- "posthog_datawarehousetable"."size_in_s3_mib"- FROM "posthog_datawarehousetable"- LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id")- WHERE ("posthog_datawarehousetable"."team_id" = 99999- AND NOT ("posthog_datawarehousetable"."deleted"- AND "posthog_datawarehousetable"."deleted" IS NOT NULL)- AND NOT ("posthog_externaldatasource"."deleted"- AND "posthog_externaldatasource"."deleted" IS NOT NULL)- AND NOT ("posthog_externaldatasource"."access_method" = 'direct'- AND "posthog_externaldatasource"."access_method" IS NOT NULL))- ORDER BY "posthog_datawarehousetable"."created_at" DESC- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.32- '''- SELECT "posthog_datawarehousejoin"."created_by_id",- "posthog_datawarehousejoin"."created_at",- "posthog_datawarehousejoin"."deleted",- "posthog_datawarehousejoin"."deleted_at",- "posthog_datawarehousejoin"."id",- "posthog_datawarehousejoin"."team_id",- "posthog_datawarehousejoin"."source_table_name",- "posthog_datawarehousejoin"."source_table_key",- "posthog_datawarehousejoin"."joining_table_name",- "posthog_datawarehousejoin"."joining_table_key",- "posthog_datawarehousejoin"."field_name",- "posthog_datawarehousejoin"."configuration"- FROM "posthog_datawarehousejoin"- WHERE ("posthog_datawarehousejoin"."team_id" = 99999- AND NOT ("posthog_datawarehousejoin"."deleted"- AND "posthog_datawarehousejoin"."deleted" IS NOT NULL))- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.33- '''- SELECT "posthog_team"."id",- "posthog_team"."uuid",- "posthog_team"."organization_id",- "posthog_team"."parent_team_id",- "posthog_team"."project_id",- "posthog_team"."api_token",- "posthog_team"."app_urls",- "posthog_team"."name",- "posthog_team"."slack_incoming_webhook",- "posthog_team"."created_at",- "posthog_team"."updated_at",- "posthog_team"."anonymize_ips",- "posthog_team"."completed_snippet_onboarding",- "posthog_team"."has_completed_onboarding_for",- "posthog_team"."onboarding_tasks",- "posthog_team"."ingested_event",- "posthog_team"."ingested_production_event",- "posthog_team"."ingested_production_event_last_checked_at",- "posthog_team"."person_processing_opt_out",- "posthog_team"."secret_api_token",- "posthog_team"."secret_api_token_backup",- "posthog_team"."session_recording_opt_in",- "posthog_team"."session_recording_sample_rate",- "posthog_team"."session_recording_minimum_duration_milliseconds",- "posthog_team"."session_recording_linked_flag",- "posthog_team"."session_recording_network_payload_capture_config",- "posthog_team"."session_recording_masking_config",- "posthog_team"."session_recording_url_trigger_config",- "posthog_team"."session_recording_url_blocklist_config",- "posthog_team"."session_recording_event_trigger_config",- "posthog_team"."session_recording_trigger_match_type_config",- "posthog_team"."session_recording_trigger_groups",- "posthog_team"."session_replay_config",- "posthog_team"."session_recording_retention_period",- "posthog_team"."conversations_enabled",- "posthog_team"."conversations_settings",- "posthog_team"."proactive_tasks_enabled",- "posthog_team"."survey_config",- "posthog_team"."surveys_opt_in",- "posthog_team"."product_tours_opt_in",- "posthog_team"."capture_console_log_opt_in",- "posthog_team"."capture_performance_opt_in",- "posthog_team"."capture_dead_clicks",- "posthog_team"."autocapture_opt_out",- "posthog_team"."autocapture_web_vitals_opt_in",- "posthog_team"."autocapture_web_vitals_allowed_metrics",- "posthog_team"."autocapture_exceptions_opt_in",- "posthog_team"."autocapture_exceptions_errors_to_ignore",- "posthog_team"."logs_settings",- "posthog_team"."llm_gateway_enabled_at",- "posthog_team"."llm_gateway_revoked_at",- "posthog_team"."heatmaps_opt_in",- "posthog_team"."receive_org_level_activity_logs",- "posthog_team"."web_analytics_pre_aggregated_tables_enabled",- "posthog_team"."web_analytics_pre_aggregated_tables_version",- "posthog_team"."flags_persistence_default",- "posthog_team"."feature_flag_confirmation_enabled",- "posthog_team"."feature_flag_confirmation_message",- "posthog_team"."default_evaluation_environments_enabled",- "posthog_team"."require_evaluation_environment_tags",- "posthog_team"."default_evaluation_contexts_enabled",- "posthog_team"."require_evaluation_contexts",- "posthog_team"."session_recording_version",- "posthog_team"."signup_token",- "posthog_team"."is_demo",- "posthog_team"."access_control",- "posthog_team"."week_start_day",- "posthog_team"."inject_web_apps",- "posthog_team"."test_account_filters",- "posthog_team"."test_account_filters_default_checked",- "posthog_team"."path_cleaning_filters",- "posthog_team"."timezone",- "posthog_team"."data_attributes",- "posthog_team"."person_display_name_properties",- "posthog_team"."live_events_columns",- "posthog_team"."recording_domains",- "posthog_team"."human_friendly_comparison_periods",- "posthog_team"."cookieless_server_hash_mode",- "posthog_team"."primary_dashboard_id",- "posthog_team"."default_data_theme",- "posthog_team"."extra_settings",- "posthog_team"."modifiers",- "posthog_team"."correlation_config",- "posthog_team"."session_recording_retention_period_days",- "posthog_team"."external_data_workspace_id",- "posthog_team"."external_data_workspace_last_synced_at",- "posthog_team"."api_query_rate_limit",- "posthog_team"."revenue_tracking_config",- "posthog_team"."drop_events_older_than",- "posthog_team"."base_currency",- "posthog_team"."experiment_recalculation_time",- "posthog_team"."default_experiment_confidence_level",- "posthog_team"."default_experiment_stats_method",- "posthog_team"."business_model",- "posthog_organization"."id",- "posthog_organization"."name",- "posthog_organization"."slug",- "posthog_organization"."logo_media_id",- "posthog_organization"."created_at",- "posthog_organization"."updated_at",- "posthog_organization"."is_active",- "posthog_organization"."is_not_active_reason",- "posthog_organization"."session_cookie_age",- "posthog_organization"."is_member_join_email_enabled",- "posthog_organization"."is_ai_data_processing_approved",- "posthog_organization"."is_ai_training_opted_in",- "posthog_organization"."is_ai_training_locked",- "posthog_organization"."is_ai_training_cta_shown",- "posthog_organization"."enforce_2fa",- "posthog_organization"."members_can_invite",- "posthog_organization"."members_can_create_projects",- "posthog_organization"."members_can_use_personal_api_keys",- "posthog_organization"."allow_publicly_shared_resources",- "posthog_organization"."default_role_id",- "posthog_organization"."plugins_access_level",- "posthog_organization"."for_internal_metrics",- "posthog_organization"."default_experiment_stats_method",- "posthog_organization"."default_anonymize_ips",- "posthog_organization"."is_hipaa",- "posthog_organization"."is_pending_deletion",- "posthog_organization"."customer_id",- "posthog_organization"."available_product_features",- "posthog_organization"."usage",- "posthog_organization"."never_drop_data",- "posthog_organization"."customer_trust_scores",- "posthog_organization"."setup_section_2_completed",- "posthog_organization"."personalization",- "posthog_organization"."domain_whitelist",- "posthog_organization"."is_platform"- FROM "posthog_team"- INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id")- WHERE "posthog_team"."id" = 99999- ORDER BY "posthog_team"."id" ASC- LIMIT 1- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.34- '''- SELECT COUNT(*)- FROM- (SELECT DISTINCT "ee_single_session_summary"."session_id" AS "session_id"- FROM "ee_single_session_summary"- WHERE "ee_single_session_summary"."team_id" = 99999) subquery- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.35+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.3'''SELECT "posthog_user"."id","posthog_user"."password",@@ -1428,7 +1097,7 @@AND "posthog_user"."id" = 99999)'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.36+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.30'''SELECT "posthog_organization"."id","posthog_organization"."name",@@ -1470,7 +1139,7 @@LIMIT 21'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.37+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.31'''SELECT "posthog_team"."id","posthog_team"."uuid",@@ -1607,7 +1276,7 @@LIMIT 21'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.38+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.32'''SELECT "posthog_organizationmembership"."id","posthog_organizationmembership"."organization_id",@@ -1658,7 +1327,7 @@LIMIT 21'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.39+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.33'''SELECT "ee_accesscontrol"."id","ee_accesscontrol"."team_id",@@ -1704,49 +1373,7 @@AND "ee_accesscontrol"."team_id" = 99999))'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.4- '''- SELECT "posthog_organization"."id",- "posthog_organization"."name",- "posthog_organization"."slug",- "posthog_organization"."logo_media_id",- "posthog_organization"."created_at",- "posthog_organization"."updated_at",- "posthog_organization"."is_active",- "posthog_organization"."is_not_active_reason",- "posthog_organization"."session_cookie_age",- "posthog_organization"."is_member_join_email_enabled",- "posthog_organization"."is_ai_data_processing_approved",- "posthog_organization"."is_ai_training_opted_in",- "posthog_organization"."is_ai_training_locked",- "posthog_organization"."is_ai_training_cta_shown",- "posthog_organization"."enforce_2fa",- "posthog_organization"."members_can_invite",- "posthog_organization"."members_can_create_projects",- "posthog_organization"."members_can_use_personal_api_keys",- "posthog_organization"."allow_publicly_shared_resources",- "posthog_organization"."default_role_id",- "posthog_organization"."plugins_access_level",- "posthog_organization"."for_internal_metrics",- "posthog_organization"."default_experiment_stats_method",- "posthog_organization"."default_anonymize_ips",- "posthog_organization"."is_hipaa",- "posthog_organization"."is_pending_deletion",- "posthog_organization"."customer_id",- "posthog_organization"."available_product_features",- "posthog_organization"."usage",- "posthog_organization"."never_drop_data",- "posthog_organization"."customer_trust_scores",- "posthog_organization"."setup_section_2_completed",- "posthog_organization"."personalization",- "posthog_organization"."domain_whitelist",- "posthog_organization"."is_platform"- FROM "posthog_organization"- WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid- LIMIT 21- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.40+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.34'''SELECT "posthog_organizationmembership"."id","posthog_organizationmembership"."organization_id",@@ -1795,7 +1422,7 @@WHERE "posthog_organizationmembership"."user_id" = 99999'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.41+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.35'''SELECT COUNT(*) AS "__count"FROM "posthog_sessionrecordingplaylist"@@ -1806,7 +1433,7 @@AND NOT "posthog_sessionrecordingplaylist"."deleted")'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.42+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.36'''SELECT "posthog_sessionrecordingplaylist"."id","posthog_sessionrecordingplaylist"."short_id",@@ -2016,7 +1643,7 @@LIMIT 100'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.43+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.37'''SELECT "posthog_sessionrecordingplaylistitem"."playlist_id" AS "playlist_id",COUNT("posthog_sessionrecordingplaylistitem"."id") AS "c"@@ -2033,7 +1660,7 @@GROUP BY 1'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.44+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.38'''SELECT "posthog_sessionrecordingplaylistitem"."playlist_id" AS "playlist_id","posthog_sessionrecordingplaylistitem"."recording_id" AS "recording_id"@@ -2047,7 +1674,7 @@5 /* ... */))'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.45+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.39'''SELECT "posthog_sessionrecordingviewed"."session_id" AS "session_id"FROM "posthog_sessionrecordingviewed"@@ -2056,149 +1683,9 @@AND "posthog_sessionrecordingviewed"."session_id" IN ('00000000-0000-0000-0000-000000000000'))'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.46- '''- SELECT COUNT(*) AS "__count"- FROM "posthog_sessionrecordingviewed"- WHERE ("posthog_sessionrecordingviewed"."team_id" = 99999- AND "posthog_sessionrecordingviewed"."user_id" = 99999)- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.47- '''- SELECT COUNT(*)- FROM- (SELECT DISTINCT "posthog_comment"."item_id" AS "item_id"- FROM "posthog_comment"- WHERE (NOT "posthog_comment"."deleted"- AND "posthog_comment"."scope" = 'Replay'- AND "posthog_comment"."team_id" = 99999- AND NOT ("posthog_comment"."item_id" IS NULL))) subquery- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.48- '''- SELECT COUNT(*)- FROM- (SELECT DISTINCT "posthog_sharingconfiguration"."recording_id" AS "recording__session_id"- FROM "posthog_sharingconfiguration"- WHERE ("posthog_sharingconfiguration"."enabled"- AND "posthog_sharingconfiguration"."team_id" = 99999- AND NOT ("posthog_sharingconfiguration"."recording_id" IS NULL))) subquery- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.49- '''- SELECT COUNT(*)- FROM- (SELECT DISTINCT ("posthog_exportedasset"."export_context" -> 'session_recording_id') AS "export_context__session_recording_id"- FROM "posthog_exportedasset"- WHERE (("posthog_exportedasset"."expires_after" >= '2025-01-01 12:00:00+00:00'::timestamptz- OR "posthog_exportedasset"."expires_after" IS NULL)- AND "posthog_exportedasset"."team_id" = 99999- AND "posthog_exportedasset"."export_context" ? 'session_recording_id'- AND NOT (("posthog_exportedasset"."export_context" -> 'session_recording_id') IS NULL)- AND NOT (("posthog_exportedasset"."export_context" -> 'session_recording_id') = '""'::jsonb- AND "posthog_exportedasset"."export_context" IS NOT NULL))) subquery- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.5+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.4'''- SELECT "posthog_team"."id",- "posthog_team"."uuid",- "posthog_team"."organization_id",- "posthog_team"."parent_team_id",- "posthog_team"."project_id",- "posthog_team"."api_token",- "posthog_team"."app_urls",- "posthog_team"."name",- "posthog_team"."slack_incoming_webhook",- "posthog_team"."created_at",- "posthog_team"."updated_at",- "posthog_team"."anonymize_ips",- "posthog_team"."completed_snippet_onboarding",- "posthog_team"."has_completed_onboarding_for",- "posthog_team"."onboarding_tasks",- "posthog_team"."ingested_event",- "posthog_team"."ingested_production_event",- "posthog_team"."ingested_production_event_last_checked_at",- "posthog_team"."person_processing_opt_out",- "posthog_team"."secret_api_token",- "posthog_team"."secret_api_token_backup",- "posthog_team"."session_recording_opt_in",- "posthog_team"."session_recording_sample_rate",- "posthog_team"."session_recording_minimum_duration_milliseconds",- "posthog_team"."session_recording_linked_flag",- "posthog_team"."session_recording_network_payload_capture_config",- "posthog_team"."session_recording_masking_config",- "posthog_team"."session_recording_url_trigger_config",- "posthog_team"."session_recording_url_blocklist_config",- "posthog_team"."session_recording_event_trigger_config",- "posthog_team"."session_recording_trigger_match_type_config",- "posthog_team"."session_recording_trigger_groups",- "posthog_team"."session_replay_config",- "posthog_team"."session_recording_retention_period",- "posthog_team"."conversations_enabled",- "posthog_team"."conversations_settings",- "posthog_team"."proactive_tasks_enabled",- "posthog_team"."survey_config",- "posthog_team"."surveys_opt_in",- "posthog_team"."product_tours_opt_in",- "posthog_team"."capture_console_log_opt_in",- "posthog_team"."capture_performance_opt_in",- "posthog_team"."capture_dead_clicks",- "posthog_team"."autocapture_opt_out",- "posthog_team"."autocapture_web_vitals_opt_in",- "posthog_team"."autocapture_web_vitals_allowed_metrics",- "posthog_team"."autocapture_exceptions_opt_in",- "posthog_team"."autocapture_exceptions_errors_to_ignore",- "posthog_team"."logs_settings",- "posthog_team"."llm_gateway_enabled_at",- "posthog_team"."llm_gateway_revoked_at",- "posthog_team"."heatmaps_opt_in",- "posthog_team"."receive_org_level_activity_logs",- "posthog_team"."web_analytics_pre_aggregated_tables_enabled",- "posthog_team"."web_analytics_pre_aggregated_tables_version",- "posthog_team"."flags_persistence_default",- "posthog_team"."feature_flag_confirmation_enabled",- "posthog_team"."feature_flag_confirmation_message",- "posthog_team"."default_evaluation_environments_enabled",- "posthog_team"."require_evaluation_environment_tags",- "posthog_team"."default_evaluation_contexts_enabled",- "posthog_team"."require_evaluation_contexts",- "posthog_team"."session_recording_version",- "posthog_team"."signup_token",- "posthog_team"."is_demo",- "posthog_team"."access_control",- "posthog_team"."week_start_day",- "posthog_team"."inject_web_apps",- "posthog_team"."test_account_filters",- "posthog_team"."test_account_filters_default_checked",- "posthog_team"."path_cleaning_filters",- "posthog_team"."timezone",- "posthog_team"."data_attributes",- "posthog_team"."person_display_name_properties",- "posthog_team"."live_events_columns",- "posthog_team"."recording_domains",- "posthog_team"."human_friendly_comparison_periods",- "posthog_team"."cookieless_server_hash_mode",- "posthog_team"."primary_dashboard_id",- "posthog_team"."default_data_theme",- "posthog_team"."extra_settings",- "posthog_team"."modifiers",- "posthog_team"."correlation_config",- "posthog_team"."session_recording_retention_period_days",- "posthog_team"."external_data_workspace_id",- "posthog_team"."external_data_workspace_last_synced_at",- "posthog_team"."api_query_rate_limit",- "posthog_team"."revenue_tracking_config",- "posthog_team"."drop_events_older_than",- "posthog_team"."base_currency",- "posthog_team"."experiment_recalculation_time",- "posthog_team"."default_experiment_confidence_level",- "posthog_team"."default_experiment_stats_method",- "posthog_team"."business_model",- "posthog_organization"."id",+ SELECT "posthog_organization"."id","posthog_organization"."name","posthog_organization"."slug","posthog_organization"."logo_media_id",@@ -2233,206 +1720,67 @@"posthog_organization"."personalization","posthog_organization"."domain_whitelist","posthog_organization"."is_platform"- FROM "posthog_team"- INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id")- WHERE "posthog_team"."id" = 99999+ FROM "posthog_organization"+ WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuidLIMIT 21'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.50- '''- SELECT "posthog_datawarehousesavedquery"."created_by_id",- "posthog_datawarehousesavedquery"."created_at",- "posthog_datawarehousesavedquery"."updated_at",- "posthog_datawarehousesavedquery"."deleted",- "posthog_datawarehousesavedquery"."deleted_at",- "posthog_datawarehousesavedquery"."id",- "posthog_datawarehousesavedquery"."name",- "posthog_datawarehousesavedquery"."team_id",- "posthog_datawarehousesavedquery"."latest_error",- "posthog_datawarehousesavedquery"."columns",- "posthog_datawarehousesavedquery"."external_tables",- "posthog_datawarehousesavedquery"."query",- "posthog_datawarehousesavedquery"."status",- "posthog_datawarehousesavedquery"."last_run_at",- "posthog_datawarehousesavedquery"."sync_frequency_interval",- "posthog_datawarehousesavedquery"."table_id",- "posthog_datawarehousesavedquery"."is_materialized",- "posthog_datawarehousesavedquery"."deleted_name",- "posthog_datawarehousesavedquery"."managed_viewset_id",- "posthog_datawarehousesavedquery"."folder_id",- "posthog_datawarehousesavedquery"."origin",- "posthog_datawarehousesavedquery"."is_test",- "posthog_datawarehousesavedquery"."expires_at",- "posthog_datawarehousetable"."created_by_id",- "posthog_datawarehousetable"."created_at",- "posthog_datawarehousetable"."updated_at",- "posthog_datawarehousetable"."deleted",- "posthog_datawarehousetable"."deleted_at",- "posthog_datawarehousetable"."id",- "posthog_datawarehousetable"."name",- "posthog_datawarehousetable"."format",- "posthog_datawarehousetable"."team_id",- "posthog_datawarehousetable"."url_pattern",- "posthog_datawarehousetable"."queryable_folder",- "posthog_datawarehousetable"."credential_id",- "posthog_datawarehousetable"."external_data_source_id",- "posthog_datawarehousetable"."columns",- "posthog_datawarehousetable"."options",- "posthog_datawarehousetable"."row_count",- "posthog_datawarehousetable"."size_in_s3_mib",- "posthog_datawarehousemanagedviewset"."created_by_id",- "posthog_datawarehousemanagedviewset"."created_at",- "posthog_datawarehousemanagedviewset"."updated_at",- "posthog_datawarehousemanagedviewset"."id",- "posthog_datawarehousemanagedviewset"."team_id",- "posthog_datawarehousemanagedviewset"."kind"- FROM "posthog_datawarehousesavedquery"- LEFT OUTER JOIN "posthog_datawarehousemanagedviewset" ON ("posthog_datawarehousesavedquery"."managed_viewset_id" = "posthog_datawarehousemanagedviewset"."id")- LEFT OUTER JOIN "posthog_datawarehousetable" ON ("posthog_datawarehousesavedquery"."table_id" = "posthog_datawarehousetable"."id")- WHERE ("posthog_datawarehousesavedquery"."team_id" = 99999- AND NOT ("posthog_datawarehousesavedquery"."deleted"- AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)- AND "posthog_datawarehousesavedquery"."managed_viewset_id" IS NULL)- ORDER BY "posthog_datawarehousesavedquery"."name" ASC+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.40+ '''+ SELECT COUNT(*) AS "__count"+ FROM "posthog_sessionrecordingviewed"+ WHERE ("posthog_sessionrecordingviewed"."team_id" = 99999+ AND "posthog_sessionrecordingviewed"."user_id" = 99999)'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.51- '''- SELECT "posthog_datawarehousesavedquery"."created_by_id",- "posthog_datawarehousesavedquery"."created_at",- "posthog_datawarehousesavedquery"."updated_at",- "posthog_datawarehousesavedquery"."deleted",- "posthog_datawarehousesavedquery"."deleted_at",- "posthog_datawarehousesavedquery"."id",- "posthog_datawarehousesavedquery"."name",- "posthog_datawarehousesavedquery"."team_id",- "posthog_datawarehousesavedquery"."latest_error",- "posthog_datawarehousesavedquery"."columns",- "posthog_datawarehousesavedquery"."external_tables",- "posthog_datawarehousesavedquery"."query",- "posthog_datawarehousesavedquery"."status",- "posthog_datawarehousesavedquery"."last_run_at",- "posthog_datawarehousesavedquery"."sync_frequency_interval",- "posthog_datawarehousesavedquery"."table_id",- "posthog_datawarehousesavedquery"."is_materialized",- "posthog_datawarehousesavedquery"."deleted_name",- "posthog_datawarehousesavedquery"."managed_viewset_id",- "posthog_datawarehousesavedquery"."folder_id",- "posthog_datawarehousesavedquery"."origin",- "posthog_datawarehousesavedquery"."is_test",- "posthog_datawarehousesavedquery"."expires_at",- "posthog_datawarehousetable"."created_by_id",- "posthog_datawarehousetable"."created_at",- "posthog_datawarehousetable"."updated_at",- "posthog_datawarehousetable"."deleted",- "posthog_datawarehousetable"."deleted_at",- "posthog_datawarehousetable"."id",- "posthog_datawarehousetable"."name",- "posthog_datawarehousetable"."format",- "posthog_datawarehousetable"."team_id",- "posthog_datawarehousetable"."url_pattern",- "posthog_datawarehousetable"."queryable_folder",- "posthog_datawarehousetable"."credential_id",- "posthog_datawarehousetable"."external_data_source_id",- "posthog_datawarehousetable"."columns",- "posthog_datawarehousetable"."options",- "posthog_datawarehousetable"."row_count",- "posthog_datawarehousetable"."size_in_s3_mib"- FROM "posthog_datawarehousesavedquery"- LEFT OUTER JOIN "posthog_datawarehousetable" ON ("posthog_datawarehousesavedquery"."table_id" = "posthog_datawarehousetable"."id")- WHERE ("posthog_datawarehousesavedquery"."team_id" = 99999- AND "posthog_datawarehousesavedquery"."origin" = 'endpoint'- AND NOT ("posthog_datawarehousesavedquery"."deleted"- AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL))+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.41+ '''+ SELECT COUNT(*)+ FROM+ (SELECT DISTINCT "posthog_comment"."item_id" AS "item_id"+ FROM "posthog_comment"+ WHERE (NOT "posthog_comment"."deleted"+ AND "posthog_comment"."scope" = 'Replay'+ AND "posthog_comment"."team_id" = 99999+ AND NOT ("posthog_comment"."item_id" IS NULL))) subquery'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.52- '''- SELECT "posthog_externaldatasource"."created_by_id",- "posthog_externaldatasource"."created_at",- "posthog_externaldatasource"."updated_at",- "posthog_externaldatasource"."deleted",- "posthog_externaldatasource"."deleted_at",- "posthog_externaldatasource"."id",- "posthog_externaldatasource"."source_id",- "posthog_externaldatasource"."connection_id",- "posthog_externaldatasource"."destination_id",- "posthog_externaldatasource"."team_id",- "posthog_externaldatasource"."sync_frequency",- "posthog_externaldatasource"."status",- "posthog_externaldatasource"."source_type",- "posthog_externaldatasource"."job_inputs",- "posthog_externaldatasource"."connection_metadata",- "posthog_externaldatasource"."are_tables_created",- "posthog_externaldatasource"."prefix",- "posthog_externaldatasource"."description",- "posthog_externaldatasource"."created_via",- "posthog_externaldatasource"."access_method",- "posthog_externaldatasource"."revenue_analytics_enabled",- "posthog_externaldatasourcerevenueanalyticsconfig"."external_data_source_id",- "posthog_externaldatasourcerevenueanalyticsconfig"."enabled",- "posthog_externaldatasourcerevenueanalyticsconfig"."include_invoiceless_charges"- FROM "posthog_externaldatasource"- LEFT OUTER JOIN "posthog_externaldatasourcerevenueanalyticsconfig" ON ("posthog_externaldatasource"."id" = "posthog_externaldatasourcerevenueanalyticsconfig"."external_data_source_id")- WHERE ("posthog_externaldatasource"."source_type" IN ('Stripe')- AND "posthog_externaldatasource"."team_id" = 99999- AND NOT ("posthog_externaldatasource"."deleted"- AND "posthog_externaldatasource"."deleted" IS NOT NULL))+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.42+ '''+ SELECT COUNT(*)+ FROM+ (SELECT DISTINCT "posthog_sharingconfiguration"."recording_id" AS "recording__session_id"+ FROM "posthog_sharingconfiguration"+ WHERE ("posthog_sharingconfiguration"."enabled"+ AND "posthog_sharingconfiguration"."team_id" = 99999+ AND NOT ("posthog_sharingconfiguration"."recording_id" IS NULL))) subquery'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.53- '''- SELECT "posthog_datawarehousetable"."created_by_id",- "posthog_datawarehousetable"."created_at",- "posthog_datawarehousetable"."updated_at",- "posthog_datawarehousetable"."deleted",- "posthog_datawarehousetable"."deleted_at",- "posthog_datawarehousetable"."id",- "posthog_datawarehousetable"."name",- "posthog_datawarehousetable"."format",- "posthog_datawarehousetable"."team_id",- "posthog_datawarehousetable"."url_pattern",- "posthog_datawarehousetable"."queryable_folder",- "posthog_datawarehousetable"."credential_id",- "posthog_datawarehousetable"."external_data_source_id",- "posthog_datawarehousetable"."columns",- "posthog_datawarehousetable"."options",- "posthog_datawarehousetable"."row_count",- "posthog_datawarehousetable"."size_in_s3_mib"- FROM "posthog_datawarehousetable"- LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id")- WHERE ("posthog_datawarehousetable"."team_id" = 99999- AND NOT ("posthog_datawarehousetable"."deleted"- AND "posthog_datawarehousetable"."deleted" IS NOT NULL)- AND NOT ("posthog_externaldatasource"."deleted"- AND "posthog_externaldatasource"."deleted" IS NOT NULL)- AND NOT ("posthog_externaldatasource"."access_method" = 'direct'- AND "posthog_externaldatasource"."access_method" IS NOT NULL))- ORDER BY "posthog_datawarehousetable"."created_at" DESC+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.43+ '''+ SELECT COUNT(*)+ FROM+ (SELECT DISTINCT ("posthog_exportedasset"."export_context" -> 'session_recording_id') AS "export_context__session_recording_id"+ FROM "posthog_exportedasset"+ WHERE (("posthog_exportedasset"."expires_after" >= '2025-01-01 12:00:00+00:00'::timestamptz+ OR "posthog_exportedasset"."expires_after" IS NULL)+ AND "posthog_exportedasset"."team_id" = 99999+ AND "posthog_exportedasset"."export_context" ? 'session_recording_id'+ AND NOT (("posthog_exportedasset"."export_context" -> 'session_recording_id') IS NULL)+ AND NOT (("posthog_exportedasset"."export_context" -> 'session_recording_id') = '""'::jsonb+ AND "posthog_exportedasset"."export_context" IS NOT NULL))) subquery'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.54- '''- SELECT "posthog_datawarehousejoin"."created_by_id",- "posthog_datawarehousejoin"."created_at",- "posthog_datawarehousejoin"."deleted",- "posthog_datawarehousejoin"."deleted_at",- "posthog_datawarehousejoin"."id",- "posthog_datawarehousejoin"."team_id",- "posthog_datawarehousejoin"."source_table_name",- "posthog_datawarehousejoin"."source_table_key",- "posthog_datawarehousejoin"."joining_table_name",- "posthog_datawarehousejoin"."joining_table_key",- "posthog_datawarehousejoin"."field_name",- "posthog_datawarehousejoin"."configuration"- FROM "posthog_datawarehousejoin"- WHERE ("posthog_datawarehousejoin"."team_id" = 99999- AND NOT ("posthog_datawarehousejoin"."deleted"- AND "posthog_datawarehousejoin"."deleted" IS NOT NULL))+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.44+ '''+ SELECT COUNT(*)+ FROM+ (SELECT DISTINCT "ee_single_session_summary"."session_id" AS "session_id"+ FROM "ee_single_session_summary"+ WHERE "ee_single_session_summary"."team_id" = 99999) subquery'''# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.55+# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.5'''SELECT "posthog_team"."id","posthog_team"."uuid",@@ -2566,17 +1914,7 @@FROM "posthog_team"INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id")WHERE "posthog_team"."id" = 99999- ORDER BY "posthog_team"."id" ASC- LIMIT 1- '''-# ----# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.56- '''- SELECT COUNT(*)- FROM- (SELECT DISTINCT "ee_single_session_summary"."session_id" AS "session_id"- FROM "ee_single_session_summary"- WHERE "ee_single_session_summary"."team_id" = 99999) subquery+ LIMIT 21'''# ---# name: TestSessionRecordingPlaylist.test_filters_playlist_by_type.6diff --git a/posthog/session_recordings/test/test_session_recording_playlist.py b/posthog/session_recordings/test/test_session_recording_playlist.pyindex 5e236cd166a1..f9441e93fb1b 100644--- a/posthog/session_recordings/test/test_session_recording_playlist.py+++ b/posthog/session_recordings/test/test_session_recording_playlist.py@@ -7,6 +7,7 @@ from posthog.test.base import APIBaseTest, QueryMatchingTest, snapshot_postgres_from unittest import mockfrom unittest.mock import MagicMock, patch+from django.core.cache import cachefrom django.db import connection, transactionfrom django.test.utils import CaptureQueriesContext@@ -34,6 +35,7 @@ from posthog.session_recordings.session_recording_playlist_api import (_empty_saved_filters_counts,precompute_recordings_counts,)+from posthog.session_recordings.synthetic_playlists import ExpiringPlaylistSourcefrom posthog.settings import (OBJECT_STORAGE_ACCESS_KEY_ID,OBJECT_STORAGE_BUCKET,@@ -904,6 +906,13 @@ class TestSessionRecordingPlaylist(APIBaseTest, QueryMatchingTest):@snapshot_postgres_queries@freeze_time("2025-01-01T12:00:00Z")def test_filters_playlist_by_type(self):+ # Prime the expiring-playlist cache so its cold-start scan (which builds the+ # warehouse HogQL Database and emits a DataWarehouseSavedQuery lookup) stays+ # out of this query snapshot. The scan runs once per hour in production; left+ # to LocMemCache state it fires or not depending on test order, making the+ # captured query set flaky.+ cache.set(ExpiringPlaylistSource._get_cache_key(self.team.pk), [], ExpiringPlaylistSource.CACHE_TTL)+# Setup playlists with different types and conditionsp_filters_explicit = SessionRecordingPlaylist.objects.create(team=self.team,diff --git a/posthog/session_recordings/test/test_synthetic_playlists.py b/posthog/session_recordings/test/test_synthetic_playlists.pyindex f43c7ee3b53a..8dac9b3e8f6b 100644--- a/posthog/session_recordings/test/test_synthetic_playlists.py+++ b/posthog/session_recordings/test/test_synthetic_playlists.py@@ -1,6 +1,8 @@-from datetime import datetime, timedelta+from datetime import UTC, datetime, timedelta+from types import SimpleNamespacefrom posthog.test.base import APIBaseTest, _create_event, flush_persons_and_events+from unittest.mock import patchfrom django.core.cache import cachefrom django.utils.timezone import now@@ -12,7 +14,7 @@ from posthog.models import Comment, SessionRecordingPlaylistfrom posthog.models.sharing_configuration import SharingConfigurationfrom posthog.models.utils import uuid7from posthog.session_recordings.models.session_recording_event import SessionRecordingViewed-from posthog.session_recordings.synthetic_playlists import FrustrationSignalsPlaylistSource+from posthog.session_recordings.synthetic_playlists import ExpiringPlaylistSource, FrustrationSignalsPlaylistSourcefrom products.exports.backend.models.exported_asset import ExportedAsset@@ -59,6 +61,33 @@ class TestSyntheticPlaylists(APIBaseTest):assert sorted(synthetic_short_ids) == sorted(expected)+ def test_expiring_playlist_caches_and_shares_one_scan(self) -> None:+ cache.clear()++ now_ts = datetime.now(UTC)+ recordings = [+ SimpleNamespace(session_id="expiring-soon", expiry_time=now_ts + timedelta(days=3)),+ SimpleNamespace(session_id="expiring-later", expiry_time=now_ts + timedelta(days=40)),+ SimpleNamespace(session_id="no-expiry", expiry_time=None),+ ]++ source = ExpiringPlaylistSource()++ with patch(+ "posthog.session_recordings.synthetic_playlists.list_recordings_from_query",+ return_value=(recordings, False, None, None),+ ) as mock_query:+ count = source.count_session_ids(self.team, self.user)+ session_ids = source.get_session_ids(self.team, self.user)+ # a second list load within the cache TTL must not re-scan+ recount = source.count_session_ids(self.team, self.user)++ assert count == 1+ assert recount == 1+ assert session_ids == ["expiring-soon"]+ # count + get_session_ids + recount share a single cached scan+ assert mock_query.call_count == 1+def test_retrieve_synthetic_playlist(self) -> None:playlist = self._get_synthetic_playlist("synthetic-watch-history")