From 050122c6655d2f1117bc7f71c5a3faf2e3f1fa37 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 30 May 2024 09:21:55 -0500 Subject: [PATCH] Use global score for top (#1202) * Use global score for comments ordered by top * Use global score for global top feed --- api/resolvers/item.js | 46 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index a5dfcf1c..cc34e4fc 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -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