Add curated posts page.

Add a curated posts page at /explore/posts/curated. Curated posts are
the most favorited posts by contributor-level users (users with
unlimited upload permissions).

Also add an order:curated tag using for use in regular searches.
This commit is contained in:
evazion
2020-02-23 16:43:06 -06:00
parent e8590afa6d
commit 463b1b734e
12 changed files with 79 additions and 35 deletions

View File

@@ -596,6 +596,16 @@ class PostQueryBuilder
when "rank"
relation = relation.order(Arel.sql("log(3, posts.score) + (extract(epoch from posts.created_at) - extract(epoch from timestamp '2005-05-24')) / 35000 DESC"))
when "curated"
contributors = User.bit_prefs_match(:can_upload_free, true)
relation = relation
.joins(:favorites)
.where(favorites: { user: contributors })
.group("posts.id")
.select("posts.*, COUNT(*) AS contributor_fav_count")
.order("contributor_fav_count DESC, posts.fav_count DESC, posts.id DESC")
when "custom"
if q[:post_id].present? && q[:post_id][0] == :in
relation = relation.find_ordered(q[:post_id][1])