Use global score for top (#1202)

* Use global score for comments ordered by top

* Use global score for global top feed
This commit is contained in:
ekzyis 2024-05-30 09:21:55 -05:00 committed by GitHub
parent 6047c37e4e
commit 050122c665
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 38 deletions

View File

@ -27,18 +27,11 @@ function commentsOrderByClause (me, models, sort) {
return 'ORDER BY "Item".created_at DESC, "Item".id DESC'
}
if (me) {
if (sort === 'top') {
return `ORDER BY COALESCE(
personal_top_score,
${orderByNumerator(models, 0)}) DESC NULLS LAST,
"Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
} else {
return `ORDER BY COALESCE(
if (me && sort === 'hot') {
return `ORDER BY COALESCE(
personal_hot_score,
${orderByNumerator(models, 0)}/POWER(GREATEST(3, EXTRACT(EPOCH FROM (now_utc() - "Item".created_at))/3600), 1.3)) DESC NULLS LAST,
"Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
}
} else {
if (sort === 'top') {
return `ORDER BY ${orderByNumerator(models, 0)} DESC NULLS LAST, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
@ -373,32 +366,10 @@ export default {
}, decodedCursor.time, decodedCursor.offset, limit, ...subArr)
break
case 'top':
if (me && (!by || by === 'zaprank') && (when === 'day' || when === 'week')) {
// personalized zaprank only goes back 7 days
items = await itemQueryWithMeta({
me,
models,
query: `
${SELECT}, GREATEST(g.tf_top_score, l.tf_top_score) AS rank
${relationClause(type)}
${joinZapRankPersonalView(me, models)}
${whereClause(
'"Item"."deletedAt" IS NULL',
subClause(sub, 5, subClauseTable(type), me, showNsfw),
typeClause(type),
whenClause(when, 'Item'),
await filterClause(me, models, type),
muteClause(me))}
ORDER BY rank DESC
OFFSET $3
LIMIT $4`,
orderBy: 'ORDER BY rank DESC'
}, ...whenRange(when, from, to || decodedCursor.time), decodedCursor.offset, limit, ...subArr)
} else {
items = await itemQueryWithMeta({
me,
models,
query: `
items = await itemQueryWithMeta({
me,
models,
query: `
${selectClause(type)}
${relationClause(type)}
${whereClause(
@ -411,9 +382,8 @@ export default {
${orderByClause(by || 'zaprank', me, models, type)}
OFFSET $3
LIMIT $4`,
orderBy: orderByClause(by || 'zaprank', me, models, type)
}, ...whenRange(when, from, to || decodedCursor.time), decodedCursor.offset, limit, ...subArr)
}
orderBy: orderByClause(by || 'zaprank', me, models, type)
}, ...whenRange(when, from, to || decodedCursor.time), decodedCursor.offset, limit, ...subArr)
break
default:
// sub so we know the default ranking