posts/show: refactor parent/child notices.

* Convert notices from helpers to partials.
* Eliminate PostSets::PostRelationship class in favor of post_sets/posts template.
* Eliminate COUNT(*) queries when calculating the number of child posts.
* Eliminate redundant parent load and parent exists queries.
This commit is contained in:
evazion
2020-01-12 17:08:59 -06:00
parent ed5caba71c
commit 40711e1d4f
7 changed files with 36 additions and 74 deletions

View File

@@ -1,24 +0,0 @@
module PostSets
class PostRelationship < PostSets::Post
attr_reader :parent, :children
def initialize(parent_id, options = {})
@parent = ::Post.where("id = ?", parent_id)
@children = ::Post.where("parent_id = ?", parent_id).order("id ASC")
if options[:include_deleted]
super("parent:#{parent_id} status:any")
else
@children = @children.where("is_deleted = ?", false)
super("parent:#{parent_id}")
end
end
def posts
@parent + @children
end
def presenter
::PostSetPresenters::Post.new(self)
end
end
end