<commit_before>class ProposalsController < ApplicationController
  include CommentableActions
  include FlagActions

  before_action :set_search_order, only: [:index]
  before_action :authenticate_user!, except: [:index, :show]

  has_orders %w{hot_score confidence_score created_at relevance}, only: :index
  has_orders %w{most_voted newest oldest}, only: :show

  load_and_authorize_resource
  respond_to :html, :js

  def index
    @filter = ResourceFilter.new(Proposal.all, params)
    @proposals = @filter.collection

    @featured_proposals = @proposals.sort_by_confidence_score.limit(3) if (@filter.search_filter.blank? && @filter.tag_filter.blank?)
    if @featured_proposals.present?
      set_featured_proposal_votes(@featured_proposals)
      @featured_proposals = @featured_proposals.send("sort_by_#{@current_order}")
      @proposals = @proposals.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id))
    end

    @proposals = @proposals.page(params[:page]).for_render.send("sort_by_#{@current_order}")
    set_resource_votes(@proposals)
  end

  def vote
    @proposal.register_vote(current_user, 'yes')
    set_proposal_votes(@proposal)
  end

  def vote_featured
    @proposal.register_vote(current_user, 'yes')
    set_featured_proposal_votes(@proposal)
  end

  private

    def proposal_params
      permitted_params = [:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key, :category_id, :subcategory_id, :scope, :district]

      if current_user.administrator?
        permitted_params << :official
      end

      params.require(:proposal).permit(permitted_params)
    end

    def resource_model
      Proposal
    end

    def set_featured_proposal_votes(proposals)
      @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {}
    end

end
<commit_msg>Don't show featured proposals collection is bellow limit<commit_after>class ProposalsController < ApplicationController
  FEATURED_PROPOSALS_LIMIT = 3
  include CommentableActions
  include FlagActions

  before_action :set_search_order, only: [:index]
  before_action :authenticate_user!, except: [:index, :show]

  has_orders %w{hot_score confidence_score created_at relevance}, only: :index
  has_orders %w{most_voted newest oldest}, only: :show

  load_and_authorize_resource
  respond_to :html, :js

  def index
    @filter = ResourceFilter.new(Proposal.all, params)
    @proposals = @filter.collection

    if @proposals.length > FEATURED_PROPOSALS_LIMIT
      @featured_proposals = @proposals.sort_by_confidence_score.limit(FEATURED_PROPOSALS_LIMIT) if (@filter.search_filter.blank? && @filter.tag_filter.blank?)
      if @featured_proposals.present?
        set_featured_proposal_votes(@featured_proposals)
        @featured_proposals = @featured_proposals.send("sort_by_#{@current_order}")
        @proposals = @proposals.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id))
      end
    end

    @proposals = @proposals.page(params[:page]).for_render.send("sort_by_#{@current_order}")
    set_resource_votes(@proposals)
  end

  def vote
    @proposal.register_vote(current_user, 'yes')
    set_proposal_votes(@proposal)
  end

  def vote_featured
    @proposal.register_vote(current_user, 'yes')
    set_featured_proposal_votes(@proposal)
  end

  private

    def proposal_params
      permitted_params = [:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key, :category_id, :subcategory_id, :scope, :district]

      if current_user.administrator?
        permitted_params << :official
      end

      params.require(:proposal).permit(permitted_params)
    end

    def resource_model
      Proposal
    end

    def set_featured_proposal_votes(proposals)
      @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {}
    end

end

{'fraction_non_alphanumeric': 0.10067788099422546, 'fraction_numerical': 0.0005021340697966357, 'mean_word_length': 4.833089311859443, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, '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': '7574842', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1335, 'n_words': 231}