Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4617,11 +4617,11 @@ describe('mutation viewPost', () => {
expect(notifyView).toBeCalledTimes(1);
});

it('should should not submit view event for articles', async () => {
it('should submit view event for articles', async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the intentional behavior flip (was should should not submit view event for articles asserting 0 calls). The auth/permission tests for the mutation are untouched — only the article-exclusion assertion changed.

loggedUser = '1';
const res = await client.mutate(MUTATION, { variables });
expect(res.errors).toBeFalsy();
expect(notifyView).toBeCalledTimes(0);
expect(notifyView).toBeCalledTimes(1);
});
});

Expand Down
18 changes: 8 additions & 10 deletions src/schema/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3408,16 +3408,14 @@ export const resolvers: IResolvers<unknown, BaseContext> = {
): Promise<GQLEmptyResponse> => {
const post = await ctx.con.getRepository(Post).findOneByOrFail({ id });
await ensureSourcePermissions(ctx, post.sourceId);
if (post.type !== PostType.Article) {
await notifyView(
ctx.log,
post.id,
ctx.userId,
ctx.req.headers['referer'],
new Date(),
post.tagsStr?.split?.(',') ?? [],
);
}
await notifyView(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed guard existed to avoid double-counting articles: their view was historically produced by the GET /r/:postId redirector when the user clicks "Read article", so viewPost deliberately no-oped for them.

Removing it is safe because dedup already happens downstream, not here: the views worker drops duplicate View rows per (userId, postId) within a one-week window, and the streak only increments once per day. Video posts have relied on exactly this for a while (they track on open and go through the redirector on click), so this puts articles on the same, already-proven path.

Also worth noting for review: ensureSourcePermissions still runs before the publish, and the mutation's API shape is unchanged — clients that don't call viewPost for articles yet (current prod frontend) are unaffected, which is why there's no deploy-order constraint with dailydotdev/apps#6380.

ctx.log,
post.id,
ctx.userId,
ctx.req.headers['referer'],
new Date(),
post.tagsStr?.split?.(',') ?? [],
);
return { _: true };
},
dismissPostFeedback: async (
Expand Down
Loading