Skip to content

Commit

Permalink
Merge branch 'develop' into feat/deprecate-tag-management
Browse files Browse the repository at this point in the history
  • Loading branch information
gitwoz committed Nov 7, 2024
2 parents c358fdd + 65f78cf commit bedd0f4
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 491 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ 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 @@ -510,7 +509,6 @@ type Tag implements Node {

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

"""Time of this tag was created."""
createdAt: DateTime!
Expand Down Expand Up @@ -2464,11 +2462,9 @@ 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: 85 additions & 120 deletions src/connectors/__test__/articleService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,41 +410,6 @@ 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 @@ -462,97 +427,97 @@ describe('latestArticles', () => {
skip: 0,
take: 10,
oss: false,
excludeSpam: false,
excludeSpam: true,
})
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: 0 additions & 15 deletions src/connectors/__test__/campaignService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,6 @@ 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
2 changes: 2 additions & 0 deletions src/connectors/articleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ export class ArticleService extends BaseService<Article> {
displayName,
userName,
paymentPointer,
ensName,
} = author
if (!userName || !displayName) {
throw new ServerError('userName or displayName is missing')
Expand Down Expand Up @@ -835,6 +836,7 @@ export class ArticleService extends BaseService<Article> {
userName,
displayName,
uri: `https://${environment.siteDomain}/@${userName}`,
ipnsKey: ensName && ipnsKey ? ipnsKey : undefined,
},
website: {
name: 'Matters',
Expand Down
Loading

0 comments on commit bedd0f4

Please sign in to comment.