Skip to content

Commit 289422c

Browse files
committed
feat(daily): only return digest posts for last 24 hours
1 parent 18938d2 commit 289422c

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

__tests__/highlights.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ describe('query dailyHeadlines', () => {
376376
status,
377377
});
378378

379+
const hoursAgo = (hours: number): Date =>
380+
new Date(Date.now() - hours * 60 * 60 * 1000);
381+
379382
beforeEach(async () => {
380383
await saveFixtures(con, User, usersFixture);
381384
await saveFixtures(con, Feed, [{ id: '1', userId: '1' }]);
@@ -405,26 +408,21 @@ describe('query dailyHeadlines', () => {
405408
'bd-old',
406409
'backend_digest',
407410
'Backend old',
408-
new Date('2026-06-19T08:00:00.000Z'),
411+
hoursAgo(20),
409412
);
410413
await saveDigestPost(
411414
'bd-new',
412415
'backend_digest',
413416
'Backend latest',
414-
new Date('2026-06-19T12:00:00.000Z'),
417+
hoursAgo(2),
415418
);
416419
await saveDigestPost(
417420
'career-d',
418421
'career_digest',
419422
'Career latest',
420-
new Date('2026-06-19T10:00:00.000Z'),
421-
);
422-
await saveDigestPost(
423-
'bdb-d',
424-
'backend_digest_b',
425-
'Blocked',
426-
new Date('2026-06-19T13:00:00.000Z'),
423+
hoursAgo(5),
427424
);
425+
await saveDigestPost('bdb-d', 'backend_digest_b', 'Blocked', hoursAgo(1));
428426

429427
const res = await client.query(DAILY_HEADLINES_QUERY);
430428

@@ -447,6 +445,20 @@ describe('query dailyHeadlines', () => {
447445
expect(res.errors).toBeFalsy();
448446
expect(res.data.dailyHeadlines.edges).toEqual([]);
449447
});
448+
449+
it('should exclude digest posts older than 24 hours', async () => {
450+
loggedUser = '1';
451+
452+
await saveDigestSource('backend_digest');
453+
await saveChannelDigest('backend', 'backend_digest', 'backend');
454+
await followDigest('backend_digest');
455+
await saveDigestPost('bd-stale', 'backend_digest', 'Stale', hoursAgo(30));
456+
457+
const res = await client.query(DAILY_HEADLINES_QUERY);
458+
459+
expect(res.errors).toBeFalsy();
460+
expect(res.data.dailyHeadlines.edges).toEqual([]);
461+
});
450462
});
451463

452464
describe('query channelDigestConfigurations', () => {

src/schema/highlights.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ContentPreferenceSource } from '../entity/contentPreference/ContentPref
2222
import { ContentPreferenceStatus } from '../entity/contentPreference/types';
2323
import { queryReadReplica } from '../common/queryReadReplica';
2424
import { Post, PostType } from '../entity/posts/Post';
25+
import { ONE_DAY_IN_SECONDS } from '../common/constants';
2526

2627
type GQLChannelDigestConfiguration = {
2728
frequency: string;
@@ -125,8 +126,8 @@ export const typeDefs = /* GraphQL */ `
125126
): PostHighlightConnection!
126127
127128
"""
128-
Get the latest digest post for each channel digest whose source the current
129-
user follows, one per channel, ordered by recency.
129+
Get the latest digest post from the last 24 hours for each channel digest
130+
whose source the current user follows, one per channel, ordered by recency.
130131
"""
131132
dailyHeadlines(first: Int, after: String): PostConnection! @auth
132133
}
@@ -283,6 +284,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = {
283284
ctx: AuthContext,
284285
info,
285286
) => {
287+
const since = new Date(Date.now() - ONE_DAY_IN_SECONDS * 1000);
286288
const latestDigestPerChannel = await queryReadReplica(
287289
ctx.con,
288290
({ queryRunner }) =>
@@ -298,8 +300,8 @@ export const resolvers: IResolvers<unknown, BaseContext> = {
298300
.innerJoin(
299301
Post,
300302
'p',
301-
'p."sourceId" = cd."sourceId" AND p.type = :postType AND p.visible = true AND p.deleted = false',
302-
{ postType: PostType.Freeform },
303+
'p."sourceId" = cd."sourceId" AND p.type = :postType AND p.visible = true AND p.deleted = false AND p."createdAt" >= :since',
304+
{ postType: PostType.Freeform, since },
303305
)
304306
.where('cp."userId" = :userId AND cp."feedId" = :userId', {
305307
userId: ctx.userId,

0 commit comments

Comments
 (0)