<commit_before>class PositionsController < ApplicationController

  protect_from_forgery

  respond_to :json
  
  def update
    raise 'Cannot update without a logged in user' if !current_user || !current_user.registration_complete

    position = Position.find params[:id]
    authorize! :update, position

    proposal = position.proposal
    ApplicationController.reset_user_activities(session, proposal) if !session.has_key?(proposal.id)

    already_published = position.published

    update_attrs = {
      :user_id => current_user.id,
      :proposal => proposal
    }

    if params[:position].has_key? :explanation
      update_attrs[:explanation] = params[:position][:explanation]
    end
    if params[:position].has_key? :stance
      update_attrs[:stance] = params[:position][:stance]
    end

    update_attrs[:published] = true
    position.update_attributes update_attrs

    params[:position][:included_points] ||= []
    params[:position][:included_points].each do |pnt|
      session[position.proposal_id][:included_points][pnt] = true
    end

    params[:position][:viewed_points] ||= []
    params[:position][:viewed_points].each do |pnt|
      session[position.proposal_id][:viewed_points].push([pnt,-1])
    end

    save_actions(position)

    position.point_inclusions = Inclusion.where(:user_id => position.user_id).where(:proposal_id => position.proposal_id).select(:point_id).map {|x| x.point_id}.compact.to_s
    #position.point_inclusions = position.inclusions(:select => [:point_id]).map {|x| x.point_id}.compact.to_s       
    position.save
    
    position.track!

    #proposal.follow!(current_user, :follow => params[:position][:follow_proposal] == 'true', :explicit => true)
    position.follow!(current_user, :follow => true, :explicit => false)
    proposal.follow!(current_user, :follow => params[:follow_proposal] == 'true', :explicit => true)

    proposal.update_metrics()
    
    alert_new_published_position(proposal, position) unless already_published

    render :json => position

  end

  def show
    if request.xhr?
      proposal = Proposal.find_by_long_id(params[:long_id])
      position = proposal.positions.published.where(:user_id => params[:user_id]).first
      user = position.user
<commit_msg>putting proposal update in delay queue<commit_after>class PositionsController < ApplicationController

  protect_from_forgery

  respond_to :json
  
  def update
    raise 'Cannot update without a logged in user' if !current_user || !current_user.registration_complete

    position = Position.find params[:id]
    authorize! :update, position

    proposal = position.proposal
    ApplicationController.reset_user_activities(session, proposal) if !session.has_key?(proposal.id)

    already_published = position.published

    update_attrs = {
      :user_id => current_user.id,
      :proposal => proposal
    }

    if params[:position].has_key? :explanation
      update_attrs[:explanation] = params[:position][:explanation]
    end
    if params[:position].has_key? :stance
      update_attrs[:stance] = params[:position][:stance]
    end

    update_attrs[:published] = true
    position.update_attributes update_attrs

    params[:position][:included_points] ||= []
    params[:position][:included_points].each do |pnt|
      session[position.proposal_id][:included_points][pnt] = true
    end

    params[:position][:viewed_points] ||= []
    params[:position][:viewed_points].each do |pnt|
      session[position.proposal_id][:viewed_points].push([pnt,-1])
    end

    save_actions(position)

    position.point_inclusions = Inclusion.where(:user_id => position.user_id).where(:proposal_id => position.proposal_id).select(:point_id).map {|x| x.point_id}.compact.to_s
    #position.point_inclusions = position.inclusions(:select => [:point_id]).map {|x| x.point_id}.compact.to_s       
    position.save
    
    position.track!

    #proposal.follow!(current_user, :follow => params[:position][:follow_proposal] == 'true', :explicit => true)
    position.follow!(current_user, :follow => true, :explicit => false)
    proposal.follow!(current_user, :follow => params[:follow_proposal] == 'true', :explicit => true)


    proposal.delay.update_metrics()
    
    alert_new_published_position(proposal, position) unless already_published

    render :json => position

  end

  def show
    if request.xhr?
      proposal = Proposal.find_by_long_id(params[:long_id])
      position = proposal.positions.published.where(:user_id => params[:user_id]).first
      user = position.user

{'fraction_non_alphanumeric': 0.12510993843447668, 'fraction_numerical': 0.00043975373790677223, 'mean_word_length': 4.252886836027714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '1996282', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1350, 'n_words': 243}