Skip to content

feat: unified view logging – count article views on post open - #4026

Open
rebelchris wants to merge 1 commit into
mainfrom
feat/unified-post-view-logging
Open

feat: unified view logging – count article views on post open#4026
rebelchris wants to merge 1 commit into
mainfrom
feat/unified-post-view-logging

Conversation

@rebelchris

@rebelchris rebelchris commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Removes the post.type !== PostType.Article guard in the viewPost GraphQL mutation (src/schema/posts.ts) so notifyView is 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/:postId redirector. 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 notifyView from viewPost.

Dedup safety: The views worker dedupes View rows 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/:postId will 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 viewPost API shape), and the frontend's viewPost call sites are unchanged, so this backend PR and the frontend PR are independently deployable in either order.

Changes

  • src/schema/posts.ts: viewPost resolver now unconditionally calls notifyView after ensureSourcePermissions, for all post types.
  • __tests__/posts.ts: replaced the test asserting articles do not trigger notifyView with 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 in describe('mutation viewPost') pass (had to run pending local migrations against the api_test DB first; local infra — postgres/redis — was available in this environment).
  • Full __tests__/posts.ts suite: 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

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>
@pulumi

pulumi Bot commented Jul 27, 2026

Copy link
Copy Markdown

🍹 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant