feat: unified view logging – count article views on post open - #4026
Open
rebelchris wants to merge 1 commit into
Open
feat: unified view logging – count article views on post open#4026rebelchris wants to merge 1 commit into
rebelchris wants to merge 1 commit into
Conversation
Removes the Article-type exclusion in the viewPost GraphQL mutation so opening a post page/modal logs a view for every post type, unifying behavior with the /r/:postId redirector. The views worker's one-week per-user/post dedup and once-per-day streak increment make duplicate sends from both producers safe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🍹 The Update (preview) for dailydotdev/api/prod (at 6d166db) was successful. Resource Changes Name Type Operation
~ vpc-native-clean-zombie-user-companies-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-updated-sync-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-opportunities-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-old-notifications-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-highlighted-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-subscription-anniversary-achievements-cron kubernetes:batch/v1:CronJob update
~ vpc-native-channel-highlights-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tags-str-cron kubernetes:batch/v1:CronJob update
~ vpc-native-squad-posts-analytics-refresh-cron kubernetes:batch/v1:CronJob update
~ vpc-native-channel-digests-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-clean-zombie-users-cron kubernetes:batch/v1:CronJob 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
~ vpc-native-materialize-yearly-best-post-archives-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generate-search-invites-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-views-cron kubernetes:batch/v1:CronJob update
- vpc-native-api-db-migration-4cf78c40 kubernetes:batch/v1:Job delete
~ vpc-native-personalized-digest-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-clean-channel-highlights-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-stale-user-transactions-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-expired-better-auth-sessions-cron kubernetes:batch/v1:CronJob update
~ vpc-native-temporal-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-current-streak-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-achievements-cron kubernetes:batch/v1:CronJob update
~ vpc-native-rotate-daily-quests-cron kubernetes:batch/v1:CronJob update
~ vpc-native-interest-scheduled-run-cron kubernetes:batch/v1:CronJob update
~ vpc-native-worker-job-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-source-public-threshold-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tag-materialized-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-analytics-history-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-hourly-notification-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generic-referral-reminder-cron kubernetes:batch/v1:CronJob update
~ vpc-native-rotate-weekly-quests-cron kubernetes:batch/v1:CronJob update
~ vpc-native-bg-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-user-posts-analytics-refresh-cron kubernetes:batch/v1:CronJob update
~ vpc-native-daily-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-personalized-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-images-cron kubernetes:batch/v1:CronJob update
... and 16 other changes |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the
post.type !== PostType.Articleguard in theviewPostGraphQL mutation (src/schema/posts.ts) sonotifyViewis called for every post type, not just non-articles.Before: Article views were only counted (view row + reading-streak day) when a user clicked "Read article," which hits the
GET /r/:postIdredirector. Opening the article post page/modal in-app did not log a view.After: Opening the post page/modal now logs a view for articles too, matching every other post type (share, freeform, video, etc.), which already called
notifyViewfromviewPost.Dedup safety: The views worker dedupes
Viewrows per(userId, postId)within a one-week window and increments the reading streak at most once per day, so a user who both opens the post and later clicks through via/r/:postIdwill not be double-counted.No deploy-order constraint: There is the companion frontend PR dailydotdev/apps#6380. Either side can deploy first — the mutation change here is additive (it doesn't change the
viewPostAPI shape), and the frontend'sviewPostcall sites are unchanged, so this backend PR and the frontend PR are independently deployable in either order.Changes
src/schema/posts.ts:viewPostresolver now unconditionally callsnotifyViewafterensureSourcePermissions, for all post types.__tests__/posts.ts: replaced the test asserting articles do not triggernotifyViewwith one asserting they do (should submit view event for articles), consistent with the existing non-article assertion. Auth/permission tests (UNAUTHENTICATED,NOT_FOUND,FORBIDDEN) untouched.Test plan
NODE_ENV=test npx jest __tests__/posts.ts --testEnvironment=node --runInBand -t "viewPost"— all 5 tests indescribe('mutation viewPost')pass (had to run pending local migrations against theapi_testDB first; local infra — postgres/redis — was available in this environment).__tests__/posts.tssuite: 365 passed, 0 failed.npx eslint src/schema/posts.ts __tests__/posts.ts --max-warnings 0— clean.pnpm run build(tsc) — clean.🤖 Generated with Claude Code