クエリ・パフォーマンスの改善(#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!
|
||||
|
||||
@@ -25,6 +25,8 @@ class Tag < ApplicationRecord
|
||||
has_many :tag_similarities, dependent: :delete_all
|
||||
|
||||
belongs_to :tag_name
|
||||
delegate :wiki_page, to: :tag_name
|
||||
|
||||
delegate :name, to: :tag_name, allow_nil: true
|
||||
validates :tag_name, presence: true
|
||||
|
||||
@@ -56,7 +58,7 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def has_wiki
|
||||
tag_name&.wiki_page.present?
|
||||
wiki_page.present?
|
||||
end
|
||||
|
||||
def self.tagme
|
||||
|
||||
Reference in New Issue
Block a user