<commit_before>module Leagues
  module Matches
    class CommsController < ApplicationController
      include MatchesCommon

      before_action only: :create do
        @match = League::Match.find(params[:match_id])
        @league = @match.league
      end
      before_action only: [:edit, :update, :edits, :destroy] do
        @comm   = League::Match::Comm.find(params[:id])
        @match  = @comm.match
        @league = @match.league
      end
      before_action :require_user_can_comm, only: :create
      before_action :require_user_can_edit_comm, only: [:edit, :update, :edits]
      before_action :require_user_can_edit_league, only: :destroy

      def create
        @comm = Comms::CreationService.call(current_user, @match, comm_params)

        if @comm.valid?
          redirect_to match_path(@match)
        else
          match_show_includes

          render '/leagues/matches/show'
        end
      end

      def edit
      end

      def update
        @comm = Comms::EditingService.call(current_user, @comm, comm_params)

        if @comm.valid?
          redirect_to match_path(@match)
        else
          render :edit
        end
      end

      def edits
        @edits = @comm.edits
      end<commit_msg>Fixed N+1 Query issue on comms edits page<commit_after>module Leagues
  module Matches
    class CommsController < ApplicationController
      include MatchesCommon

      before_action only: :create do
        @match = League::Match.find(params[:match_id])
        @league = @match.league
      end
      before_action only: [:edit, :update, :edits, :destroy] do
        @comm   = League::Match::Comm.find(params[:id])
        @match  = @comm.match
        @league = @match.league
      end
      before_action :require_user_can_comm, only: :create
      before_action :require_user_can_edit_comm, only: [:edit, :update, :edits]
      before_action :require_user_can_edit_league, only: :destroy

      def create
        @comm = Comms::CreationService.call(current_user, @match, comm_params)

        if @comm.valid?
          redirect_to match_path(@match)
        else
          match_show_includes

          render '/leagues/matches/show'
        end
      end

      def edit
      end

      def update
        @comm = Comms::EditingService.call(current_user, @comm, comm_params)

        if @comm.valid?
          redirect_to match_path(@match)
        else
          render :edit
        end
      end

      def edits
        @edits = @comm.edits.includes(:user)
      end
{'fraction_non_alphanumeric': 0.08928571428571429, 'fraction_numerical': 0.0003968253968253968, 'mean_word_length': 2.2697795071335927, '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': '3949331', 'n_tokens_mistral': 765, 'n_tokens_neox': 738, 'n_words': 176}