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' return 'ORDER BY "Item".created_at DESC, "Item".id DESC'
} }
if (me) { if (me && sort === 'hot') {
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( return `ORDER BY COALESCE(
personal_hot_score, personal_hot_score,
${orderByNumerator(models, 0)}/POWER(GREATEST(3, EXTRACT(EPOCH FROM (now_utc() - "Item".created_at))/3600), 1.3)) DESC NULLS LAST, ${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` "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
}
} else { } else {
if (sort === 'top') { if (sort === 'top') {
return `ORDER BY ${orderByNumerator(models, 0)} DESC NULLS LAST, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC` return `ORDER BY ${orderByNumerator(models, 0)} DESC NULLS LAST, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
@ -373,28 +366,6 @@ export default {
}, decodedCursor.time, decodedCursor.offset, limit, ...subArr) }, decodedCursor.time, decodedCursor.offset, limit, ...subArr)
break break
case 'top': 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({ items = await itemQueryWithMeta({
me, me,
models, models,
@ -413,7 +384,6 @@ export default {
LIMIT $4`, LIMIT $4`,
orderBy: orderByClause(by || 'zaprank', me, models, type) orderBy: orderByClause(by || 'zaprank', me, models, type)
}, ...whenRange(when, from, to || decodedCursor.time), decodedCursor.offset, limit, ...subArr) }, ...whenRange(when, from, to || decodedCursor.time), decodedCursor.offset, limit, ...subArr)
}
break break
default: default:
// sub so we know the default ranking // sub so we know the default ranking