only count comments from people other than the video author

pull/3662/head
Rigel Kent 2021-01-25 04:32:39 +01:00 committed by Chocobozzz
parent 5bcbcbe338
commit 28eeb811c4
2 changed files with 22 additions and 4 deletions

View File

@ -270,6 +270,7 @@
<select id="instanceDefaultClientRoute" formControlName="defaultClientRoute" class="form-control">
<option i18n value="/videos/overview">Discover videos</option>
<option i18n value="/videos/trending">Trending videos</option>
<option i18n value="/videos/hot">Hot videos</option>
<option i18n value="/videos/most-liked">Most liked videos</option>
<option i18n value="/videos/recently-added">Recently added videos</option>
<option i18n value="/videos/local">Local videos</option>

View File

@ -268,21 +268,38 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
like: 3,
dislike: 3,
view: 1 / 12,
comment: 6
comment: 2 // a comment takes more time than a like to do, but can be done multiple times
}
joins.push('LEFT JOIN "videoComment" ON "video"."id" = "videoComment"."videoId"')
cte.push( // TODO: exclude blocklisted comments
'"totalCommentsWithoutVideoAuthor" AS (' +
'SELECT "video"."id", ' +
'COUNT("replies"."id") - (' +
'SELECT COUNT("authorReplies"."id") ' +
'FROM "videoComment" AS "authorReplies" ' +
'LEFT JOIN "account" ON "account"."id" = "authorReplies"."accountId" ' +
'LEFT JOIN "videoChannel" ON "videoChannel"."accountId" = "account"."id" ' +
'WHERE "video"."channelId" = "videoChannel"."id" ' +
') as "value" ' +
'FROM "videoComment" AS "replies" ' +
'LEFT JOIN "video" ON "video"."id" = "replies"."videoId" ' +
'WHERE "replies"."videoId" = "video"."id" ' +
'GROUP BY "video"."id"' +
')'
)
joins.push('LEFT JOIN "totalCommentsWithoutVideoAuthor" ON "video"."id" = "totalCommentsWithoutVideoAuthor"."id"')
attributes.push(
`LOG(GREATEST(1, "video"."likes" - 1)) * ${weights.like} ` + // likes (+)
`- LOG(GREATEST(1, "video"."dislikes" - 1)) * ${weights.dislike} ` + // dislikes (-)
`+ LOG("video"."views" + 1) * ${weights.view} ` + // views (+)
`+ LOG(GREATEST(1, COUNT(DISTINCT "videoComment"."id") - 1)) * ${weights.comment} ` + // comments (+)
`+ LOG(GREATEST(1, "totalCommentsWithoutVideoAuthor"."value")) * ${weights.comment} ` + // comments (+)
'+ (SELECT EXTRACT(epoch FROM "video"."publishedAt") / 47000) ' + // base score (in number of half-days)
'AS "score"'
)
group = 'GROUP BY "video"."id"'
group = 'GROUP BY "video"."id", "totalCommentsWithoutVideoAuthor"."value"'
}
if (options.historyOfUser) {