mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-12-14 03:03:35 +00:00
* Use post excerpt for best posts to avoid giant posts ruining it * Make sure short emojis (e.g. `😂`) render in best posts and best topics * Make images show in best post excerpts (requires core change) * Fix invite action error, using column that doesn't exist * Add missing # for top category slugs * Refactor report service + controller a little to make it easier to figure out what went wrong if it fails, and to use the guardian user Copies a couple of fixes from https://github.com/discourse/discourse-rewind/pull/28 to make things work locally, the conflicts will be easy to resolve. **Best topics before** <img width="977" height="712" alt="image" src="https://github.com/user-attachments/assets/e120507f-d0d8-44f0-b242-e1056084ef03" /> **Best topics after** <img width="969" height="648" alt="image" src="https://github.com/user-attachments/assets/dd13f6ac-35df-4e9a-907e-9ed5102843b6" /> **Categories before** <img width="904" height="465" alt="image" src="https://github.com/user-attachments/assets/0d15e73d-3534-4836-b776-2c97381e58ef" /> **Categories after** <img width="925" height="466" alt="image" src="https://github.com/user-attachments/assets/3d6e4eae-32ed-4f11-a4f4-090e4473ebe9" />
32 lines
938 B
Ruby
32 lines
938 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseRewind
|
|
module Action
|
|
class BestPosts < BaseReport
|
|
def call
|
|
best_posts =
|
|
Post
|
|
.where(user_id: user.id)
|
|
.where(created_at: date)
|
|
.where(deleted_at: nil)
|
|
.where("post_number > 1")
|
|
.order("like_count DESC NULLS LAST, created_at ASC")
|
|
.limit(3)
|
|
.select(:post_number, :topic_id, :like_count, :reply_count, :raw, :cooked)
|
|
.map do |post|
|
|
{
|
|
post_number: post.post_number,
|
|
topic_id: post.topic_id,
|
|
like_count: post.like_count,
|
|
reply_count: post.reply_count,
|
|
excerpt:
|
|
post.excerpt(200, { strip_links: true, remap_emoji: true, keep_images: true }),
|
|
}
|
|
end
|
|
|
|
{ data: best_posts, identifier: "best-posts" }
|
|
end
|
|
end
|
|
end
|
|
end
|