diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 4ac83c1cc..4aa343a35 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -11,8 +11,8 @@ module CommentsHelper comment.deleted ? 0 : comment.user_id end - def tree_for(comment, commentable) - nested_comments(tree: comment.subtree.includes(:user).arrange, commentable: commentable, is_view_root: true) + def tree_for(comment, sub_comments, commentable) + nested_comments(tree: { comment => sub_comments }, commentable: commentable, is_view_root: true) end private diff --git a/app/models/comment.rb b/app/models/comment.rb index 1e5f6fa3d..961fd7e0e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -128,6 +128,10 @@ class Comment < ApplicationRecord commentable_type: commentable_type) end + def self.tree_for(commentable, limit = 0) + commentable.comments.includes(:user).arrange(order: "score DESC").to_a[0..limit - 1].to_h + end + def path "/#{user.username}/comment/#{id_code_generated}" rescue StandardError diff --git a/app/views/articles/_full_comment_area.html.erb b/app/views/articles/_full_comment_area.html.erb index 7c745532c..975f27286 100644 --- a/app/views/articles/_full_comment_area.html.erb +++ b/app/views/articles/_full_comment_area.html.erb @@ -1,6 +1,6 @@ -<% cache("whole-comment-area-#{@article.id}-#{@article.last_comment_at}-#{@article.show_comments}", :expires_in => 2.hours) do %> +<% cache("whole-comment-area-#{@article.id}-#{@article.last_comment_at}-#{@article.show_comments}", expires_in: 2.hours) do %>
- <% if @article.show_comments%> + <% if @article.show_comments %>