<commit_before>require 'numeric'
class Debate < ActiveRecord::Base
  include ActsAsParanoidAliases
  default_scope { order('created_at DESC') }

  apply_simple_captcha
  TITLE_LENGTH = Debate.columns.find { |c| c.name == 'title' }.limit

  acts_as_votable
  acts_as_commentable
  acts_as_taggable
  acts_as_paranoid column: :hidden_at

  belongs_to :author, class_name: 'User', foreign_key: 'author_id'

  validates :title, presence: true
  validates :description, presence: true
  validates :author, presence: true

  validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

  before_validation :sanitize_description
  before_validation :sanitize_tag_list

  # Ahoy setup
  visitable # Ahoy will automatically assign visit_id on create

  def self.search(params)
    if params[:tag]
      tagged_with(params[:tag])
    else
      all
    end
  end

  def likes
    get_likes.size
  end

  def dislikes
    get_dislikes.size
  end

  def total_votes
    votes_for.size
  end

  def editable?
    total_votes == 0
  end

  def editable_by?(user)
    editable? && author == user
  end

  def description
    super.try :html_safe
  end

  def tag_list_with_limit(limit = nil)
    tags.most_used(limit).pluck :name
  end

  def tags_count_out_of_limit(limit = nil)
    return 0 unless limit

    count = tags.count - limit
    count < 0 ? 0 : count
  end

  protected

  def sanitize_description
    self.description = WYSIWYGSanitizer.new.sanitize(description)
  end

  def sanitize_tag_list
    self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
  end

end
<commit_msg>changes to unambiguous order declaration. Specified as a string referred table of 'created_at' was ambiguous, index failed when filtering by tag<commit_after>require 'numeric'
class Debate < ActiveRecord::Base
  include ActsAsParanoidAliases
  default_scope { order(created_at: :desc) }

  apply_simple_captcha
  TITLE_LENGTH = Debate.columns.find { |c| c.name == 'title' }.limit

  acts_as_votable
  acts_as_commentable
  acts_as_taggable
  acts_as_paranoid column: :hidden_at

  belongs_to :author, class_name: 'User', foreign_key: 'author_id'

  validates :title, presence: true
  validates :description, presence: true
  validates :author, presence: true

  validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

  before_validation :sanitize_description
  before_validation :sanitize_tag_list

  # Ahoy setup
  visitable # Ahoy will automatically assign visit_id on create

  def self.search(params)
    if params[:tag]
      tagged_with(params[:tag])
    else
      all
    end
  end

  def likes
    get_likes.size
  end

  def dislikes
    get_dislikes.size
  end

  def total_votes
    votes_for.size
  end

  def editable?
    total_votes == 0
  end

  def editable_by?(user)
    editable? && author == user
  end

  def description
    super.try :html_safe
  end

  def tag_list_with_limit(limit = nil)
    tags.most_used(limit).pluck :name
  end

  def tags_count_out_of_limit(limit = nil)
    return 0 unless limit

    count = tags.count - limit
    count < 0 ? 0 : count
  end

  protected

  def sanitize_description
    self.description = WYSIWYGSanitizer.new.sanitize(description)
  end

  def sanitize_tag_list
    self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
  end

end

{'fraction_non_alphanumeric': 0.07140714071407141, 'fraction_numerical': 0.0024002400240024004, 'mean_word_length': 3.6564245810055866, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5859467', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1126, 'n_words': 284}