Skip to content

Commit

Permalink
Merge pull request #4221 from thematters/revert-4216-revert-4210-feat…
Browse files Browse the repository at this point in the history
…/spam-for-web-next

Revert "Revert "feat(spam): disable spam detection for campaign and search""
  • Loading branch information
gitwoz authored Nov 15, 2024
2 parents 8b90267 + 7359cef commit a0e509f
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 140 deletions.
4 changes: 4 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ type Article implements Node & PinnableWork {

"""Related articles to this article."""
relatedArticles(input: ConnectionArgs!): ArticleConnection!
relatedArticlesExcludeSpam(input: ConnectionArgs!): ArticleConnection!

"""Donation-related articles to this article."""
relatedDonationArticles(input: RelatedDonationArticlesInput!): ArticleConnection!
Expand Down Expand Up @@ -548,6 +549,7 @@ type Tag implements Node {

"""List of how many articles were attached with this tag."""
articles(input: TagArticlesInput!): ArticleConnection!
articlesExcludeSpam(input: TagArticlesInput!): ArticleConnection!

"""This value determines if this article is selected by this tag or not."""
selected(input: TagSelectedInput!): Boolean!
Expand Down Expand Up @@ -2583,9 +2585,11 @@ type Recommendation {

"""Global articles sort by publish time."""
newest(input: ConnectionArgs!): ArticleConnection!
newestExcludeSpam(input: ConnectionArgs!): ArticleConnection!

"""Global articles sort by latest activity time."""
hottest(input: ConnectionArgs!): ArticleConnection!
hottestExcludeSpam(input: ConnectionArgs!): ArticleConnection!

"""'In case you missed it' recommendation."""
icymi(input: ConnectionArgs!): ArticleConnection!
Expand Down
205 changes: 120 additions & 85 deletions src/connectors/__test__/articleService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,41 @@ describe('quicksearch', () => {
})
expect(excluded.length).toBe(0)
})
test('spam are excluded', async () => {
const [article] = await articleService.createArticle({
title: 'test spam',
content: '',
authorId: '1',
})
// const { nodes: nodes } = await articleService.searchV3({
// key: 'spam',
// take: 1,
// skip: 0,
// quicksearch: true,
// })
// expect(nodes.length).toBe(1)
// expect(nodes[0].id).toBe(article.id)

const spamThreshold = 0.5
await systemService.setFeatureFlag({
name: FEATURE_NAME.spam_detection,
flag: FEATURE_FLAG.on,
value: spamThreshold,
})

await atomService.update({
table: 'article',
where: { id: article.id },
data: { spamScore: spamThreshold + 0.1 },
})
// const { nodes: excluded } = await articleService.searchV3({
// key: 'spam',
// take: 1,
// skip: 0,
// quicksearch: true,
// })
// expect(excluded.length).toBe(0)
})
})

test('countReaders', async () => {
Expand All @@ -427,97 +462,97 @@ describe('latestArticles', () => {
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
excludeSpam: false,
})
expect(articles.length).toBeGreaterThan(0)
expect(articles[0].id).toBeDefined()
expect(articles[0].authorId).toBeDefined()
expect(articles[0].state).toBeDefined()
})
test('spam are excluded', async () => {
const articles = await articleService.latestArticles({
maxTake: 500,
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
})
const spamThreshold = 0.5
await systemService.setFeatureFlag({
name: FEATURE_NAME.spam_detection,
flag: FEATURE_FLAG.on,
value: spamThreshold,
})
// spam flag is on but no detected articles
const articles1 = await articleService.latestArticles({
maxTake: 500,
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
})
expect(articles1).toEqual(articles)

// spam detected
await atomService.update({
table: 'article',
where: { id: articles[0].id },
data: { spamScore: spamThreshold + 0.1 },
})
const articles2 = await articleService.latestArticles({
maxTake: 500,
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
})
expect(articles2.map(({ id }) => id)).not.toContain(articles[0].id)

// mark as not spam
await atomService.update({
table: 'article',
where: { id: articles[0].id },
data: { isSpam: false },
})
const articles3 = await articleService.latestArticles({
maxTake: 500,
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
})
expect(articles3.map(({ id }) => id)).toContain(articles[0].id)

// ham detected
await atomService.update({
table: 'article',
where: { id: articles[1].id },
data: { spamScore: spamThreshold - 0.1 },
})
const articles4 = await articleService.latestArticles({
maxTake: 500,
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
})
expect(articles4.map(({ id }) => id)).toContain(articles[1].id)

// mark as spam
await atomService.update({
table: 'article',
where: { id: articles[1].id },
data: { isSpam: true },
})
const articles5 = await articleService.latestArticles({
maxTake: 500,
skip: 0,
take: 10,
oss: false,
excludeSpam: true,
})
expect(articles5.map(({ id }) => id)).not.toContain(articles[1].id)
})
// test('spam are excluded', async () => {
// const articles = await articleService.latestArticles({
// maxTake: 500,
// skip: 0,
// take: 10,
// oss: false,
// excludeSpam: true,
// })
// const spamThreshold = 0.5
// await systemService.setFeatureFlag({
// name: FEATURE_NAME.spam_detection,
// flag: FEATURE_FLAG.on,
// value: spamThreshold,
// })
// // spam flag is on but no detected articles
// const articles1 = await articleService.latestArticles({
// maxTake: 500,
// skip: 0,
// take: 10,
// oss: false,
// excludeSpam: true,
// })
// expect(articles1).toEqual(articles)

// // spam detected
// await atomService.update({
// table: 'article',
// where: { id: articles[0].id },
// data: { spamScore: spamThreshold + 0.1 },
// })
// const articles2 = await articleService.latestArticles({
// maxTake: 500,
// skip: 0,
// take: 10,
// oss: false,
// excludeSpam: true,
// })
// expect(articles2.map(({ id }) => id)).not.toContain(articles[0].id)

// // mark as not spam
// await atomService.update({
// table: 'article',
// where: { id: articles[0].id },
// data: { isSpam: false },
// })
// const articles3 = await articleService.latestArticles({
// maxTake: 500,
// skip: 0,
// take: 10,
// oss: false,
// excludeSpam: true,
// })
// expect(articles3.map(({ id }) => id)).toContain(articles[0].id)

// // ham detected
// await atomService.update({
// table: 'article',
// where: { id: articles[1].id },
// data: { spamScore: spamThreshold - 0.1 },
// })
// const articles4 = await articleService.latestArticles({
// maxTake: 500,
// skip: 0,
// take: 10,
// oss: false,
// excludeSpam: true,
// })
// expect(articles4.map(({ id }) => id)).toContain(articles[1].id)

// // mark as spam
// await atomService.update({
// table: 'article',
// where: { id: articles[1].id },
// data: { isSpam: true },
// })
// const articles5 = await articleService.latestArticles({
// maxTake: 500,
// skip: 0,
// take: 10,
// oss: false,
// excludeSpam: true,
// })
// expect(articles5.map(({ id }) => id)).not.toContain(articles[1].id)
// })
})

describe('findResponses', () => {
Expand Down
15 changes: 15 additions & 0 deletions src/connectors/__test__/campaignService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ describe('find and count articles', () => {
data: { state: ARTICLE_STATE.active },
})
})
// test('spam are excluded', async () => {
// const spamThreshold = 0.5
// const _articles1 = await campaignService.findArticles(campaign.id)

// await atomService.update({
// table: 'article',
// where: { id: articles[0].id },
// data: { spamScore: spamThreshold + 0.1 },
// })

// const _articles2 = await campaignService.findArticles(campaign.id, {
// spamThreshold,
// })
// expect(_articles2.length).toBe(_articles1.length - 1)
// })
})

describe('application', () => {
Expand Down
Loading

0 comments on commit a0e509f

Please sign in to comment.