diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 865eadced..a9e7325eb 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -15,9 +15,10 @@ class DebatesController < ApplicationController def show set_debate_votes(@debate) @commentable = @debate - @comments = @debate.comments.roots.recent.page(params[:page]).for_render - # TODO limit this list to the paginated root comment's children once we have ancestry - all_visible_comments = @debate.comments + @root_comments = @debate.comments.roots.recent.page(params[:page]).per(10).for_render + @comments = @root_comments.inject([]){|all, root| all + root.descendants} + + all_visible_comments = @root_comments + @comments set_comment_flags(all_visible_comments) end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 300a07921..314518e0b 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -12,4 +12,9 @@ module CommentsHelper parent_id.blank? ? dom_id(commentable) : "comment_#{parent_id}" end + def children_of_in(parent, comments) + return [] if comments.blank? + comments.select{|c| c.parent_id == parent.id} + end + end \ No newline at end of file diff --git a/app/models/comment.rb b/app/models/comment.rb index fe57ee95f..422d39f8d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,4 @@ class Comment < ActiveRecord::Base - #acts_as_nested_set scope: [:commentable_id, :commentable_type], counter_cache: :children_count acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases acts_as_votable @@ -80,14 +79,6 @@ class Comment < ActiveRecord::Base moderator_id.present? end - # TODO: faking counter cache since there is a bug with acts_as_nested_set :counter_cache - # Remove when https://github.com/collectiveidea/awesome_nested_set/issues/294 is fixed - # and reset counters using - # > Comment.find_each { |comment| Comment.reset_counters(comment.id, :children) } - def children_count - children.count - end - def after_hide commentable_type.constantize.reset_counters(commentable_id, :comments) end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index ba9e99151..37a80d830 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -2,7 +2,7 @@
<%= t("debates.comment.deleted") %>