<commit_before>module Georgia
  class MessagesController < Georgia::ApplicationController


    def show
      @message = Georgia::Mailer::Message.find(params[:id]).decorate
      authorize @message
    end

    def index
      authorize Georgia::Mailer::Message
      redirect_to georgia.search_messages_path
    end

    def search
      authorize Georgia::Mailer::Message
      search_definition = Georgia::Mailer::MessageSearch.new(params).definition
      @search = Georgia::Mailer::Message.search(search_definition).page(params[:page])
      @messages = Georgia::Mailer::MessageDecorator.decorate_collection(@search.records)
    end

    def destroy
      set_messages
      authorize @messages
      messages_count = @messages.length
      if @messages.destroy_all
        render_success("#{'Message'.pluralize(messages_count)} successfully deleted.")
      else
        render_error('Oups. Something went wrong.')
      end
    end

    def destroy_all_spam<commit_msg>Redirect to :search action after delete to avoid record not found<commit_after>module Georgia
  class MessagesController < Georgia::ApplicationController


    def show
      begin
        @message = Georgia::Mailer::Message.find(params[:id]).decorate
        authorize @message
      rescue ActiveRecord::RecordNotFound
        authorize Georgia::Mailer::Message
        redirect_to search_messages_path, alert: 'This message could not be found.'
      end
    end

    def index
      authorize Georgia::Mailer::Message
      redirect_to georgia.search_messages_path
    end

    def search
      authorize Georgia::Mailer::Message
      search_definition = Georgia::Mailer::MessageSearch.new(params).definition
      @search = Georgia::Mailer::Message.search(search_definition).page(params[:page])
      @messages = Georgia::Mailer::MessageDecorator.decorate_collection(@search.records)
    end

    def destroy
      set_messages
      authorize @messages
      messages_count = @messages.length
      if @messages.destroy_all
        render_success("#{'Message'.pluralize(messages_count)} successfully deleted.")
      else
        render_error('Oups. Something went wrong.')
      end
    end

    def destroy_all_spam
{'fraction_non_alphanumeric': 0.08632439800090867, 'fraction_numerical': 0.0, 'mean_word_length': 3.4484848484848483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2881658', 'n_tokens_mistral': 579, 'n_tokens_neox': 567, 'n_words': 126}