クエリ・パフォーマンスの改善(#258) (#259)
#258 #258 #258 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #259
This commit was merged in pull request #259.
This commit is contained in:
@@ -30,13 +30,15 @@ class Post < ApplicationRecord
|
||||
super(options).merge(thumbnail: nil)
|
||||
end
|
||||
|
||||
def related(limit: nil)
|
||||
ids = post_similarities.select(:target_post_id).order(cos: :desc)
|
||||
def related limit: nil
|
||||
ids = post_similarities.order(cos: :desc)
|
||||
ids = ids.limit(limit) if limit
|
||||
ids = ids.pluck(:target_post_id)
|
||||
return [] if ids.empty?
|
||||
return Post.none if ids.empty?
|
||||
|
||||
Post.where(id: ids).order(Arel.sql("FIELD(id, #{ ids.join(',') })"))
|
||||
Post.where(id: ids)
|
||||
.with_attached_thumbnail
|
||||
.order(Arel.sql("FIELD(posts.id, #{ ids.join(',') })"))
|
||||
end
|
||||
|
||||
def resized_thumbnail!
|
||||
|
||||
Reference in New Issue
Block a user