Skip to content

Commit

Permalink
refactor: more adjustments to popular (#2566)
Browse files Browse the repository at this point in the history
  • Loading branch information
idoshamun authored Dec 23, 2024
1 parent 0e32cf1 commit 7a2aee9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
25 changes: 21 additions & 4 deletions __tests__/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,23 @@ describe('query anonymousFeed', () => {
loggedUser = '1';

nock('http://localhost:6000')
.post('/popular', {
.post('/feed.json', {
total_pages: 1,
page_size: 10,
fresh_page_size: '4',
offset: 0,
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' }],
Expand All @@ -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, {
Expand Down Expand Up @@ -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',
Expand All @@ -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' }],
Expand Down Expand Up @@ -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' }],
Expand Down
15 changes: 13 additions & 2 deletions src/integrations/feed/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,20 @@ const opts: Options = {
export const feedGenerators: Partial<Record<FeedVersion, FeedGenerator>> =
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,
Expand Down
1 change: 1 addition & 0 deletions src/integrations/feed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum FeedConfigName {
VectorV27 = 'vector_v27',
PostSimilarity = 'post_similarity',
CustomFeedV1 = 'custom_feed_v1',
Popular = 'popular',
}

export type FeedProvider = {
Expand Down
6 changes: 3 additions & 3 deletions src/schema/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1541,9 +1541,9 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<

const feedGenerator = filters
? new FeedGenerator(
popularFeedClient,
feedClient,
new FeedLocalConfigGenerator(
{},
{ feed_config_name: FeedConfigName.Popular },
{
includeAllowedTags: true,
includePostTypes: true,
Expand Down

0 comments on commit 7a2aee9

Please sign in to comment.