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

@@ -0,0 +1,8 @@
This post has <%= link_to pluralize(children.length, "child"), posts_path(tags: "parent:#{parent.id}") %>
(<%= link_to_wiki "learn more", "help:post_relationships" %>)
<%= link_to("« hide", "#", id: "has-children-relationship-preview-link") %>
<div id="has-children-relationship-preview">
<%= post_previews_html([parent, *children], tags: "parent:#{parent.id}", show_deleted: true) %>
</div>

View File

@@ -55,17 +55,15 @@
</div>
<% end %>
<% if post.parent_id && post.parent_exists? %>
<% if post.parent.present? %>
<div class="notice notice-small post-notice post-notice-child">
<%= has_parent_message(post, @parent_post_set) %>
<div id="has-parent-relationship-preview"><%= @parent_post_set.presenter.post_previews_html(self) %></div>
<%= render "posts/partials/show/parent_notice", parent: post.parent, children: @sibling_posts.to_a %>
</div>
<% end %>
<% if post.has_visible_children? %>
<div class="notice notice-small post-notice post-notice-parent">
<%= has_children_message(post, @children_post_set) %>
<div id="has-children-relationship-preview"><%= @children_post_set.presenter.post_previews_html(self) %></div>
<%= render "posts/partials/show/child_notice", parent: post, children: @child_posts.to_a %>
</div>
<% end %>

View File

@@ -0,0 +1,14 @@
This post belongs to a <%= link_to "parent", posts_path(tags: "parent:#{parent.id}") %> <% "(deleted)" if parent.is_deleted? %>
<% children.length.tap do |children_count| %>
<% if children_count > 1 %>
and has <%= link_to pluralize(children_count - 1, "sibling"), posts_path(tags: "parent:#{parent.id}") %>
<% end %>
<% end %>
(<%= link_to_wiki "learn more", "help:post_relationships" %>)
<%= link_to "« hide", "#", id: "has-parent-relationship-preview-link" %>
<div id="has-parent-relationship-preview">
<%= post_previews_html([parent, *children], tags: "parent:#{parent.id}", show_deleted: true) %>
</div>