<commit_before>module Trade
  class Admin::PaymentsController < Admin::BaseController
    before_action :set_payment, only: [:show, :edit, :update, :analyze, :adjust, :destroy]

    def dashboard
    end

    def index
      q_params = {}
      q_params.merge! default_params
      q_params.merge! params.permit(:type, :state, :id, :buyer_identifier, :buyer_bank, :payment_uuid, 'buyer_name-like', 'payment_orders.state', 'orders.uuid')

      @payments = Payment.default_where(q_params).order(id: :desc).page(params[:page])
    end

    def new
      @payment = Payment.new

      if params[:order_id]
        @order = Order.find params[:order_id]
        @payment.total_amount = @order.amount
      end
      @payment.payment_uuid = UidHelper.nsec_uuid('PAY')
    end

    def create
      if params[:order_id].present?
        @order = Order.find params[:order_id]
        @payment = @order.payments.build(payment_params)
      else
        @payment = Payment.new(payment_params)
      end

      if @payment.save
        render 'create'
      else
        render :new, locals: { model: @payment }, status: :unprocessable_entity
      end
    end

    def analyze
      @payment.analyze_payment_method
    end
<commit_msg>fix payment methods n+1<commit_after>module Trade
  class Admin::PaymentsController < Admin::BaseController
    before_action :set_payment, only: [:show, :edit, :update, :analyze, :adjust, :destroy]

    def dashboard
    end

    def index
      q_params = {}
      q_params.merge! default_params
      q_params.merge! params.permit(:type, :state, :id, :buyer_identifier, :buyer_bank, :payment_uuid, 'buyer_name-like', 'payment_orders.state', 'orders.uuid')

      @payments = Payment.includes(:payment_methods).default_where(q_params).order(id: :desc).page(params[:page])
    end

    def new
      @payment = Payment.new

      if params[:order_id]
        @order = Order.find params[:order_id]
        @payment.total_amount = @order.amount
      end
      @payment.payment_uuid = UidHelper.nsec_uuid('PAY')
    end

    def create
      if params[:order_id].present?
        @order = Order.find params[:order_id]
        @payment = @order.payments.build(payment_params)
      else
        @payment = Payment.new(payment_params)
      end

      if @payment.save
        render 'create'
      else
        render :new, locals: { model: @payment }, status: :unprocessable_entity
      end
    end

    def analyze
      @payment.analyze_payment_method
    end

{'fraction_non_alphanumeric': 0.11218335343787696, 'fraction_numerical': 0.0004020908725371934, 'mean_word_length': 2.89358372456964, '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': '3307984', 'n_tokens_mistral': 790, 'n_tokens_neox': 765, 'n_words': 167}