Skip to content

Commit

Permalink
fix: change digest to use posts sorting first
Browse files Browse the repository at this point in the history
to use the new popular ranking algo. also fixes empty digests if there are no new topics created in the past 24 hours but there are topics with posts
  • Loading branch information
barisusakli committed Apr 2, 2024
1 parent 6e0d669 commit 3aae923
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/user/digest.js
Expand Up @@ -183,20 +183,23 @@ async function getTermTopics(term, uid) {
start: 0,
stop: 199,
term: term,
sort: 'votes',
sort: 'posts',
teaserPost: 'first',
});
data.topics = data.topics.filter(topic => topic && !topic.deleted);

const top = data.topics.filter(t => t.votes > 0).slice(0, 10);
const topTids = top.map(t => t.tid);

const popular = data.topics
.filter(t => t.postcount > 1 && !topTids.includes(t.tid))
.filter(t => t.postcount > 1)
.sort((a, b) => b.postcount - a.postcount)
.slice(0, 10);
const popularTids = popular.map(t => t.tid);

const top = data.topics
.filter(t => t.votes > 0 && !popularTids.includes(t.tid))
.sort((a, b) => b.votes - a.votes)
.slice(0, 10);
const topTids = top.map(t => t.tid);

const recent = data.topics
.filter(t => !topTids.includes(t.tid) && !popularTids.includes(t.tid))
.sort((a, b) => b.lastposttime - a.lastposttime)
Expand Down

0 comments on commit 3aae923

Please sign in to comment.