<commit_before>class ProposalsDiscussionPluginPublicController < ApplicationController

  needs_profile

  before_filter :set_rand_cookie

  def load_proposals
    holder = profile.articles.find(params[:holder_id])
    page = (params[:page] || 1).to_i

    set_seed
    @proposals = holder.proposals.public.reorder('random()')
    @proposals = @proposals.page(page).per_page(5)

    unless @proposals.empty?
      render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => @proposals, :holder => holder, :page => page+1}
    else
      render :text => ''
    end
  end

  private

  def set_seed
    #XXX postgresql specific
    seed_val = profile.connection.quote(cookies[:_noosfero_proposals_discussion_rand_seed])
    profile.connection.execute("select setseed(#{seed_val})")
  end

  def set_rand_cookie
    return if cookies[:_noosfero_proposals_discussion_rand_seed].present?
    cookies[:_noosfero_proposals_discussion_rand_seed] = {value: rand, expires: Time.now + 600}
  end

end<commit_msg>proposals_discussion: set cookie on first proposals page<commit_after>class ProposalsDiscussionPluginPublicController < ApplicationController

  needs_profile

  def load_proposals
    holder = profile.articles.find(params[:holder_id])
    page = (params[:page] || 1).to_i
    set_rand_cookie if page == 1

    set_seed
    @proposals = holder.proposals.public.reorder('random()')
    @proposals = @proposals.page(page).per_page(5)

    unless @proposals.empty?
      render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => @proposals, :holder => holder, :page => page+1}
    else
      render :text => ''
    end
  end

  private

  def set_seed
    #XXX postgresql specific
    seed_val = profile.connection.quote(cookies[:_noosfero_proposals_discussion_rand_seed])
    profile.connection.execute("select setseed(#{seed_val})")
  end

  def set_rand_cookie
    cookies[:_noosfero_proposals_discussion_rand_seed] = {value: rand, expires: Time.now + 600}
  end

end
{'fraction_non_alphanumeric': 0.1083086053412463, 'fraction_numerical': 0.006429277942631058, 'mean_word_length': 4.542465753424658, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '5222389', 'n_tokens_mistral': 698, 'n_tokens_neox': 659, 'n_words': 122}