From 7a2aee96463aedd6dcaf130d559752150080d39a Mon Sep 17 00:00:00 2001 From: Ido Shamun Date: Mon, 23 Dec 2024 19:32:44 +0200 Subject: [PATCH] refactor: more adjustments to popular (#2566) --- __tests__/feeds.ts | 25 +++++++++++++++++++++---- src/integrations/feed/generators.ts | 15 +++++++++++++-- src/integrations/feed/types.ts | 1 + src/schema/feeds.ts | 6 +++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/__tests__/feeds.ts b/__tests__/feeds.ts index a8e4bd2ce..eb5765451 100644 --- a/__tests__/feeds.ts +++ b/__tests__/feeds.ts @@ -435,7 +435,7 @@ describe('query anonymousFeed', () => { loggedUser = '1'; nock('http://localhost:6000') - .post('/popular', { + .post('/feed.json', { total_pages: 1, page_size: 10, fresh_page_size: '4', @@ -443,7 +443,15 @@ describe('query anonymousFeed', () => { user_id: '1', source_types: ['machine', 'squad'], allowed_languages: ['en'], + feed_config_name: 'popular', min_day_range: 14, + allowed_content_curations: [ + 'news', + 'release', + 'opinion', + 'comparison', + 'story', + ], }) .reply(200, { data: [{ post_id: 'p1' }, { post_id: 'p4' }], @@ -457,7 +465,7 @@ describe('query anonymousFeed', () => { it('should safetly handle a case where the feed is empty', async () => { loggedUser = '1'; - nock('http://localhost:6000').post('/popular').reply(200, { + nock('http://localhost:6000').post('/feed.json').reply(200, { data: [], }); const res = await client.query(QUERY, { @@ -522,7 +530,7 @@ describe('query anonymousFeed', () => { ]); nock('http://localhost:6000') - .post('/popular', { + .post('/feed.json', { total_pages: 1, page_size: 10, fresh_page_size: '4', @@ -532,7 +540,15 @@ describe('query anonymousFeed', () => { user_id: '1', source_types: ['machine', 'squad'], allowed_languages: ['en'], + feed_config_name: 'popular', min_day_range: 14, + allowed_content_curations: [ + 'news', + 'release', + 'opinion', + 'comparison', + 'story', + ], }) .reply(200, { data: [{ post_id: 'p1' }, { post_id: 'p4' }], @@ -3295,13 +3311,14 @@ describe('query feedPreview', () => { loggedUser = '1'; nock('http://localhost:6000') - .post('/popular', { + .post('/feed.json', { user_id: '1', page_size: 20, offset: 0, total_pages: 1, fresh_page_size: '7', allowed_tags: ['javascript', 'webdev'], + feed_config_name: 'popular', }) .reply(200, { data: [{ post_id: 'p1' }, { post_id: 'p4' }], diff --git a/src/integrations/feed/generators.ts b/src/integrations/feed/generators.ts index 90989df28..2f9945e97 100644 --- a/src/integrations/feed/generators.ts +++ b/src/integrations/feed/generators.ts @@ -93,9 +93,20 @@ const opts: Options = { export const feedGenerators: Partial> = Object.freeze({ popular: new FeedGenerator( - popularFeedClient, + feedClient, new FeedPreferencesConfigGenerator( - { ...baseFeedConfig, min_day_range: 14 }, + { + ...baseFeedConfig, + feed_config_name: FeedConfigName.Popular, + min_day_range: 14, + allowed_content_curations: [ + 'news', + 'release', + 'opinion', + 'comparison', + 'story', + ], + }, { includePostTypes: true, includeBlockedSources: true, diff --git a/src/integrations/feed/types.ts b/src/integrations/feed/types.ts index be9bcdcc4..af2d63610 100644 --- a/src/integrations/feed/types.ts +++ b/src/integrations/feed/types.ts @@ -16,6 +16,7 @@ export enum FeedConfigName { VectorV27 = 'vector_v27', PostSimilarity = 'post_similarity', CustomFeedV1 = 'custom_feed_v1', + Popular = 'popular', } export type FeedProvider = { diff --git a/src/schema/feeds.ts b/src/schema/feeds.ts index d5311c9bb..465c58ad9 100644 --- a/src/schema/feeds.ts +++ b/src/schema/feeds.ts @@ -80,7 +80,7 @@ import { FeedLofnConfigGenerator, } from '../integrations/feed/configs'; import { counters } from '../telemetry'; -import { lofnClient, popularFeedClient } from '../integrations/feed/generators'; +import { lofnClient } from '../integrations/feed/generators'; import { ContentPreferenceStatus } from '../entity/contentPreference/types'; import { ContentPreferenceSource } from '../entity/contentPreference/ContentPreferenceSource'; import { randomUUID } from 'crypto'; @@ -1541,9 +1541,9 @@ export const resolvers: IResolvers = traceResolvers< const feedGenerator = filters ? new FeedGenerator( - popularFeedClient, + feedClient, new FeedLocalConfigGenerator( - {}, + { feed_config_name: FeedConfigName.Popular }, { includeAllowedTags: true, includePostTypes: true,