+ '+ (SELECT (EXTRACT(epoch FROM "video"."publishedAt") - 1446156582) / 47000) ' // base score (in number of half-days)
+
+ if (options.trendingAlgorithm === 'best' && options.user) {
+ joins.push(
+ 'LEFT JOIN "userVideoHistory" ON "video"."id" = "userVideoHistory"."videoId" AND "userVideoHistory"."userId" = :bestUser'
+ )
+ replacements.bestUser = options.user.id
+
+ attribute += `+ POWER(COUNT(DISTINCT "userVideoHistory"."id"), 2.0) * ${weights.history} `
+ }
+
+ attribute += 'AS "score"'
+ attributes.push(attribute)