Phuks-co / throat

Open Source link aggregator and discussion platform powering Phuks
https://phuks.co
MIT License
73 stars 32 forks source link

Add the option to sort comments by "best" #443

Closed happy-river closed 2 years ago

happy-river commented 2 years ago

To combat the problem of the oldest comments on a post typically having the highest score, because they are upvoted first and then remain at the top for more people to see, implement a "best" comment sort which weights comment scores by the number of viewers, along the lines of the method described in How Not To Sort By Average Rating.

That scoring formula works by comparing positive ratings to total ratings. Reddit uses the sum of upvotes and downvotes for total ratings, but that would not work well for any of the throat instances that I know of, because too many comments have zero downvotes. To get a number for total ratings, add a SubPostCommentView model to keep track of which users have seen which comments, and add a route and some JavaScript to add rows to the table whenever a comment is shown to a user in a context where that user can vote on a comment (the single-post view of a non-archived post, and in user notifications). Cache the number of views for each comment, and the calculated best score for each comment in the SubPostComment table.

Since "best" scores cannot be calculated by this method for comments without view counts, do not include the "best" sort option for posts made before the SubPostCommentView table is created. Older posts will default to "top" sort, and newer posts will default to "best" sort. Older posts made sticky by mods will have the option of toggling "top" and "new" sort, and newer sticky posts will have a "best"/"new" toggle.

The SubPostCommentView table could also be used in the future to highlight new/unread comments when a user views a post for the second or later time. Since I'm estimating that our large instance could accumulate as many as 250,000 rows in this table each day, we will probably want to limit that functionality to non-archived posts, and are planning on deploying a separate task to periodically delete SubPostCommentView records from comments on archived posts.

happy-river commented 2 years ago

I fixed the merge conflicts and added a pid field to SubPostCommentView to simplify the query needed to delete old views. In the process I noticed that the migration rollback was not deleting the best_comment_sort_init entry from SiteMetadata so if you used and rolled back the migration in the previous version of this PR, you should either remove that row from SiteMetadata manually or run the migration in this PR, roll it back, and then run it again.