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:
@@ -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
|
||||
Reference in New Issue
Block a user