<commit_before>require_dependency "flyover_comments/application_controller"
require_dependency "flyover_comments/authorization"

module FlyoverComments
  class CommentsController < ApplicationController
    include FlyoverComments::Authorization
    include FlyoverComments::Concerns::CommentFiltering
    include FlyoverComments::Concerns::CommentAlerts

    respond_to :json, only: [:create, :update, :index]
    respond_to :html, only: [:create, :show]
    respond_to :js, only: [:destroy, :show, :update]

    def index
      load_filtered_comments_list
      authorize_flyover_comment_index!
      respond_with @comments do |format|
        format.html{
          render partial: "flyover_comments/comments/comments", locals: { commentable: commentable, comments: @comments }
        }
      end
    end

    def create
      @comment = FlyoverComments::Comment.new(comment_params)
      @comment._user = _flyover_comments_current_user
      @comment.commentable = commentable
      @comment.parent = parent
      authorize_flyover_comment_creation!

      flash_key = @comment.save ? :success : :error
      process_comment_creation(@comment) if @comment.persisted?
      respond_with @comment do |format|
        format.html{ redirect_to :back, :flash => { flash_key => t("flyover_comments.comments.flash.create.#{flash_key.to_s}") } }
        format.json{
          if @comment.errors.any?
            render json: { errors: @comment.errors }, status: :unprocessable_entity
          else
            render partial: "flyover_comments/comments/comment", locals: { comment: @comment }
          end
        }
      end
    end

    def show
      @comment = FlyoverComments::Comment.find(params[:id])
      @top_level_comment = @comment.parent || @comment
      params[:page] ||= @comment.page unless params[:is_child]
      @children = @top_level_comment.children.with_includes.page(params[:page])

      authorize_flyover_comment_show!
      if pagination_request?
        render partial: "flyover_comments/comments/paginated_replies", locals: { children: @children, comment: @comment, collapsed: false}
      end
    end

    def update
      @comment = FlyoverComments::Comment.find(params[:id])
      @comment.assign_attributes(comment_params)
      authorize_flyover_comment_update!
      @comment.save
      respond_with @comment do |format|
        format.json{
          if @comment.errors.any?
            render json: { errors: @comment.errors }, status: :unprocessable_entity
          else
            render partial: "flyover_comments/comments/comment", locals: { comment: @comment }
          end
        }
      end
    end

    def destroy
      @comment = FlyoverComments::Comment.find(params[:id])
      if params[:hard_delete] == "true"<commit_msg>add one more with_includes<commit_after>require_dependency "flyover_comments/application_controller"
require_dependency "flyover_comments/authorization"

module FlyoverComments
  class CommentsController < ApplicationController
    include FlyoverComments::Authorization
    include FlyoverComments::Concerns::CommentFiltering
    include FlyoverComments::Concerns::CommentAlerts

    respond_to :json, only: [:create, :update, :index]
    respond_to :html, only: [:create, :show]
    respond_to :js, only: [:destroy, :show, :update]

    def index
      load_filtered_comments_list
      authorize_flyover_comment_index!
      respond_with @comments do |format|
        format.html{
          render partial: "flyover_comments/comments/comments", locals: { commentable: commentable, comments: @comments }
        }
      end
    end

    def create
      @comment = FlyoverComments::Comment.new(comment_params)
      @comment._user = _flyover_comments_current_user
      @comment.commentable = commentable
      @comment.parent = parent
      authorize_flyover_comment_creation!

      flash_key = @comment.save ? :success : :error
      process_comment_creation(@comment) if @comment.persisted?
      respond_with @comment do |format|
        format.html{ redirect_to :back, :flash => { flash_key => t("flyover_comments.comments.flash.create.#{flash_key.to_s}") } }
        format.json{
          if @comment.errors.any?
            render json: { errors: @comment.errors }, status: :unprocessable_entity
          else
            render partial: "flyover_comments/comments/comment", locals: { comment: @comment }
          end
        }
      end
    end

    def show
      @comment = FlyoverComments::Comment.with_includes.find(params[:id])
      @top_level_comment = @comment.parent || @comment
      params[:page] ||= @comment.page unless params[:is_child]
      @children = @top_level_comment.children.with_includes.page(params[:page])

      authorize_flyover_comment_show!
      if pagination_request?
        render partial: "flyover_comments/comments/paginated_replies", locals: { children: @children, comment: @comment, collapsed: false}
      end
    end

    def update
      @comment = FlyoverComments::Comment.find(params[:id])
      @comment.assign_attributes(comment_params)
      authorize_flyover_comment_update!
      @comment.save
      respond_with @comment do |format|
        format.json{
          if @comment.errors.any?
            render json: { errors: @comment.errors }, status: :unprocessable_entity
          else
            render partial: "flyover_comments/comments/comment", locals: { comment: @comment }
          end
        }
      end
    end

    def destroy
      @comment = FlyoverComments::Comment.find(params[:id])
      if params[:hard_delete] == "true"
{'fraction_non_alphanumeric': 0.09808140577371346, 'fraction_numerical': 0.0, 'mean_word_length': 3.2161753590325017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523177', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1547, 'n_words': 328}