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:
8
app/views/posts/partials/show/_child_notice.html.erb
Normal file
8
app/views/posts/partials/show/_child_notice.html.erb
Normal 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>
|
||||
@@ -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 %>
|
||||
|
||||
|
||||
14
app/views/posts/partials/show/_parent_notice.html.erb
Normal file
14
app/views/posts/partials/show/_parent_notice.html.erb
Normal 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>
|
||||
Reference in New Issue
Block a user