feat: canonicalize highlights across channels#3838
Conversation
|
🍹 The Update (preview) for dailydotdev/api/prod (at 36769ef) was successful. ✨ Neo ExplanationThis is a significant schema migration and event system refactor that replaces per-channel highlight rows with a canonical-highlight + placement-join-table model. The primary risk is the destructive migration (legacy table dropped, `reason` column removed, unique key changed) running during a live rolling deployment, where a brief overlap with old-schema writer code could cause constraint violations. 🟡 Moderate RiskThis PR refactors the channel highlights system to a canonical data model: a single 🟡 Warning — Destructive database migration running at deploy time The 🟡 Warning — Deployment ordering risk The old 🔵 Info — PubSub subscription cutover The four old subscriptions ( 🔵 Info — New A net-new worker subscription is added on the Resource Changes Name Type Operation
~ vpc-native-update-tags-str-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-trending-cron kubernetes:batch/v1:CronJob update
+ api-sub-api.major-highlight-tweet-v2 gcp:pubsub/subscription:Subscription create
~ vpc-native-clean-zombie-opportunities-cron kubernetes:batch/v1:CronJob update
~ vpc-native-personalized-digest-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-clean-gifted-plus-cron kubernetes:batch/v1:CronJob update
~ vpc-native-materialize-monthly-best-post-archives-cron kubernetes:batch/v1:CronJob update
+ api-sub-api.major-headline-added-notification-v2 gcp:pubsub/subscription:Subscription create
~ vpc-native-clean-stale-user-transactions-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generate-search-invites-cron kubernetes:batch/v1:CronJob update
- api-sub-api.major-headline-added-notification gcp:pubsub/subscription:Subscription delete
~ vpc-native-hourly-notification-cron kubernetes:batch/v1:CronJob update
~ vpc-native-materialize-yearly-best-post-archives-cron kubernetes:batch/v1:CronJob update
~ vpc-native-private-deployment kubernetes:apps/v1:Deployment update
+ vpc-native-api-db-migration-aafa0f5e kubernetes:batch/v1:Job create
~ vpc-native-temporal-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-user-profile-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generic-referral-reminder-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-updated-sync-cron kubernetes:batch/v1:CronJob update
~ vpc-native-channel-digests-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-daily-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-current-streak-cron kubernetes:batch/v1:CronJob update
~ vpc-native-expire-super-agent-trial-cron kubernetes:batch/v1:CronJob update
~ vpc-native-rotate-daily-quests-cron kubernetes:batch/v1:CronJob update
~ vpc-native-ws-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-tag-materialized-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-channel-highlights-cron kubernetes:batch/v1:CronJob update
- api-sub-api.new-highlight-real-time gcp:pubsub/subscription:Subscription delete
- vpc-native-api-db-migration-601d1ed0 kubernetes:batch/v1:Job delete
~ vpc-native-calculate-top-readers-cron kubernetes:batch/v1:CronJob update
~ vpc-native-rotate-weekly-quests-cron kubernetes:batch/v1:CronJob update
- vpc-native-api-clickhouse-migration-601d1ed0 kubernetes:batch/v1:Job delete
+ vpc-native-api-clickhouse-migration-aafa0f5e kubernetes:batch/v1:Job create
~ vpc-native-check-analytics-report-cron kubernetes:batch/v1:CronJob update
~ vpc-native-channel-highlights-cron kubernetes:batch/v1:CronJob update
- api-sub-api.generate-channel-highlight gcp:pubsub/subscription:Subscription delete
~ vpc-native-sync-subscription-with-cio-cron kubernetes:batch/v1:CronJob update
~ vpc-native-bg-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-views-cron kubernetes:batch/v1:CronJob update
... and 20 other changes |
What changed
post_highlightrow per post plus a newpost_highlight_channelplacement tableapi.v1.post-highlightedflow with a canonicalapi.v1.highlight-createdtopic and migrated the dependent workersWhy
The previous model treated channel as part of the highlight identity. That duplicated highlights across channels, forced deduplication in read paths, and missed coverage because each channel was generated independently.
This change makes highlights canonical first, evaluates candidate stories once, and keeps channel membership as placement metadata.
Impact
/highlightscontinues to be significance-filtered, but now reads canonical highlights directlyValidation
NODE_ENV=test pnpm run db:migrate:resetNODE_ENV=test npx jest __tests__/highlights.ts __tests__/workers/generateChannelHighlight.ts __tests__/workers/newHighlightRealTime.ts __tests__/cron/cleanChannelHighlights.ts __tests__/workers/majorHighlightTweet.ts __tests__/cron/channelHighlights.ts __tests__/sitemaps.ts __tests__/workers/cdc/primary.ts --testEnvironment=node --runInBand --modulePathIgnorePatterns='<rootDir>/build/'pnpm run buildNotes