<commit_before>require 'timeout'

class IdeasController < ApplicationController

  # Authentication
  before_filter :login_required
  #, :except => [:index, :show, :create]      # create not included here b/c it will redirect to login page AFTER saving
  before_filter :oauthenticate, :unless => :logged_in?                    # If no other login was applied, use oauth if present (even for index/show/create)

  # Authorization
  before_filter :check_visibility, :only => [:show]
  before_filter :check_ownership, :only => [:update]

  # Content cleanup & population
  before_filter :strip_example_text
  before_filter :add_search_feed, :only => :index
  before_filter :add_comments_feed, :only => [:show, :update]

  param_accessible :idea => [:title, :description, :tag_names, :current_id, :document ]

  make_resourceful do
    actions :new, :create, :show, :update

    before :create do
      @idea.inventor = current_user
      @idea.ip = request.remote_ip
      @idea.user_agent = request.user_agent
      if params[:tags]
        # User can enter tags as free-form text, or using client-side JS. We need to merge tags from the two sources.
        @idea.tags += params[:tags].values.map{ |tag| Tag.from_string(tag) }.flatten
      end
    end

    after :create do

      if @idea.valid? && @idea.inventor
        # Users automatically vote for their own ideas:
        @idea.add_vote!(@idea.inventor)
        UserMailer.deliver_idea_posted_to_followers(user,idea)
        if @idea.inventor
                  #UserMailer.delay({:run_at => 3.seconds.from_now}).idea_posted_to_followers(@idea.inventor, @idea)
          #Delayed::Job.enqueue IdeaPostedFollowerJob.new(@idea.inventor,@idea), 3, 5.minutes.from_now
         Delayed::Job.enqueue IdeaPostedFollowerJob.new(@idea.inventor, @idea), 5  , 3.seconds.from_now
        end

        if TWITTER_ENABLED && @idea.inventor.linked_to_twitter? && @idea.inventor.tweet_ideas?
          Delayed::Job.enqueue TweetIdeaJob.new(@idea, idea_url(@idea, :title_in_url => false))
        end

        if FACEBOOK_ENABLED && @idea.inventor.linked_to_facebook? && @idea.inventor.facebook_post_ideas?

          # Facebook regularly expires its access tokens. We attach the last one we got the user, but
          # if they're not currently logged in to Facebook, there's no guarantee it will work. So we delay
          # our attempt to post to FB unless we were able to get an up-to-date access token on this request.
          #<commit_msg>small changes<commit_after>require 'timeout'

class IdeasController < ApplicationController

  # Authentication
  before_filter :login_required
  #, :except => [:index, :show, :create]      # create not included here b/c it will redirect to login page AFTER saving
  before_filter :oauthenticate, :unless => :logged_in?                    # If no other login was applied, use oauth if present (even for index/show/create)

  # Authorization
  before_filter :check_visibility, :only => [:show]
  before_filter :check_ownership, :only => [:update]

  # Content cleanup & population
  before_filter :strip_example_text
  before_filter :add_search_feed, :only => :index
  before_filter :add_comments_feed, :only => [:show, :update]

  param_accessible :idea => [:title, :description, :tag_names, :current_id, :document ]

  make_resourceful do
    actions :new, :create, :show, :update

    before :create do
      @idea.inventor = current_user
      @idea.ip = request.remote_ip
      @idea.user_agent = request.user_agent
      if params[:tags]
        # User can enter tags as free-form text, or using client-side JS. We need to merge tags from the two sources.
        @idea.tags += params[:tags].values.map{ |tag| Tag.from_string(tag) }.flatten
      end
    end

    after :create do

      if @idea.valid? && @idea.inventor
        # Users automatically vote for their own ideas:
        @idea.add_vote!(@idea.inventor)
        UserMailer.deliver_idea_posted_to_followers(user,idea)
        if @idea.inventor
                  #UserMailer.delay({:run_at => 3.seconds.from_now}).idea_posted_to_followers(@idea.inventor, @idea)
          #Delayed::Job.enqueue IdeaPostedFollowerJob.new(@idea.inventor,@idea), 3, 5.minutes.from_now
        # Delayed::Job.enqueue IdeaPostedFollowerJob.new(@idea.inventor, @idea), 5  , 3.seconds.from_now
        end

        if TWITTER_ENABLED && @idea.inventor.linked_to_twitter? && @idea.inventor.tweet_ideas?
          Delayed::Job.enqueue TweetIdeaJob.new(@idea, idea_url(@idea, :title_in_url => false))
        end

        if FACEBOOK_ENABLED && @idea.inventor.linked_to_facebook? && @idea.inventor.facebook_post_ideas?

          # Facebook regularly expires its access tokens. We attach the last one we got the user, but
          # if they're not currently logged in to Facebook, there's no guarantee it will work. So we delay
          # our attempt to post to FB unless we were able to get an up-to-date access token on this request.
          #
{'fraction_non_alphanumeric': 0.1014667470363673, 'fraction_numerical': 0.0020092425155716293, 'mean_word_length': 3.276632302405498, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3933929', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1518, 'n_words': 427}