Merge pull request #4568 from Growstuff/memory-usage-4

Posts - memory usage
This commit is contained in:
Daniel O'Connor
2026-04-26 19:05:56 +09:30
committed by GitHub

View File

@@ -49,9 +49,10 @@ class Post < ApplicationRecord
# return posts sorted by recent activity
def self.recently_active
Post.order(created_at: :desc).sort do |a, b|
b.recent_activity <=> a.recent_activity
end
left_joins(:comments)
.select('posts.*, COALESCE(MAX(comments.created_at), posts.created_at) AS last_activity_at')
.group('posts.id')
.order(Arel.sql('last_activity_at DESC'))
end
def owner_id