perf: add indexes for top slow queries#3641
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🍹 The Update (preview) for dailydotdev/api/prod (at ac7433a) was successful. ✨ Neo ExplanationThis is a standard application deployment rolling out a new version across all 7 services, 32 cron jobs, and triggering fresh DB and ClickHouse schema migration jobs in the production Kubernetes cluster.Root Cause AnalysisA new version of the application has been built and is being deployed to production. All resources are being updated to roll out the new container image across every service and scheduled job in the cluster. Dependency ChainThe new application version cascades uniformly across the entire stack:
Risk AnalysisNo stateful resources (databases, storage buckets, persistent volumes) are being modified or deleted. The migration jobs (DB and ClickHouse) involve running schema migrations against live databases, which carries inherent risk if the migrations are destructive or non-backwards-compatible — but this is a standard part of the deployment pipeline. Kubernetes Deployments will perform rolling updates, so there is no expected downtime for the running services. Resource Changes Name Type Operation
~ vpc-native-update-current-streak-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-calculate-top-readers-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-posts-analytics-refresh-cron kubernetes:batch/v1:CronJob update
+ vpc-native-api-db-migration-f07346c8 kubernetes:batch/v1:Job create
~ vpc-native-update-source-tag-view-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-user-companies-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-users-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-gifted-plus-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tags-str-cron kubernetes:batch/v1:CronJob update
~ vpc-native-expire-super-agent-trial-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-achievement-rarity-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-history-day-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-hourly-notification-cron kubernetes:batch/v1:CronJob update
~ vpc-native-validate-active-users-cron kubernetes:batch/v1:CronJob update
~ vpc-native-daily-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-highlighted-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-trending-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-analytics-history-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-worker-job-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-personalized-digest-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-bg-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-personalized-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generate-search-invites-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generic-referral-reminder-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-source-public-threshold-cron kubernetes:batch/v1:CronJob update
~ vpc-native-ws-deployment kubernetes:apps/v1:Deployment update
+ vpc-native-api-clickhouse-migration-f07346c8 kubernetes:batch/v1:Job create
~ vpc-native-user-profile-updated-sync-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-stale-user-transactions-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-opportunities-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tag-recommendations-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-images-cron kubernetes:batch/v1:CronJob update
- vpc-native-api-db-migration-39593f76 kubernetes:batch/v1:Job delete
~ vpc-native-temporal-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-private-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-check-analytics-report-cron kubernetes:batch/v1:CronJob update
~ vpc-native-squad-posts-analytics-refresh-cron kubernetes:batch/v1:CronJob update
... and 4 other changes |
Cannot use CONCURRENTLY inside a transaction (TypeORM migrations run in a transaction). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
pg_stat_statements, prioritized by total execution timeCREATE INDEX CONCURRENTLYto avoid table locks in productionIndexes
IDX_user_marketing_cta_userId_readAt_nulluser_marketing_cta(userId) WHERE readAt IS NULLIDX_view_userId_postId_timestamp_descview(userId, postId, timestamp DESC)IDX_post_relation_relatedPostId_createdAtpost_relation(relatedPostId, createdAt)postId)IDX_source_gin_namesourcenameIDX_source_gin_handlesourcehandleTest plan
pg_stat_statementsshows improved mean/total times for targeted queries after deploymentEXPLAIN ANALYZEuses the new indexes for the marketing CTA and view insert paths🤖 Generated with Claude Code