<commit_before># coding: utf-8
require 'uri'
require 'net/http'

class Article < Content
  include PublifyGuid
  include ConfigManager

  serialize :settings, Hash

  content_fields :body, :extended

  validates :guid, uniqueness: true
  validates :title, presence: true

  has_many :pings, -> { order('created_at ASC') }, dependent: :destroy
  has_many :trackbacks, -> { order('created_at ASC') }, dependent: :destroy
  has_many :feedback, -> { order('created_at DESC') }
  has_many :resources, -> { order('created_at DESC') }, dependent: :nullify
  has_many :triggers, as: :pending_item
  has_many :comments, -> { order('created_at ASC') }, dependent: :destroy do
    # Get only ham or presumed_ham comments
    def ham
      where(state: %w(presumed_ham ham))
    end

    # Get only spam or presumed_spam comments
    def spam
      where(state: %w(presumed_spam spam))
    end
  end

  has_many :published_comments, -> { where(published: true).order('created_at ASC') }, class_name: 'Comment'
  has_many :published_trackbacks, -> { where(published: true).order('created_at ASC') }, class_name: 'Trackback'
  has_many :published_feedback, -> { where(published: true).order('created_at ASC') }, class_name: 'Feedback'

  has_and_belongs_to_many :tags, join_table: 'articles_tags'

  before_create :create_guid
  before_save :set_published_at, :set_permalink
  after_save :post_trigger, :keywords_to_tags, :shorten_url

  scope :drafts, -> { where(state: 'draft').order('created_at DESC') }
  scope :child_of, ->(article_id) { where(parent_id: article_id) }
  scope :published_at, ->(time_params) { published.where(published_at: PublifyTime.delta(*time_params)).order('published_at DESC') }
  scope :published_since, ->(time) { published.where('published_at > ?', time).order('published_at DESC') }
  scope :withdrawn, -> { where(state: 'withdrawn').order('published_at DESC') }
  scope :pending, -> { where('state = ? and published_at > ?', 'publication_pending', Time.now).order('published_at DESC') }

  scope :bestof, lambda {
    joins(:feedback).<commit_msg>Remove semi-duplicate comment scope helpers<commit_after># coding: utf-8
require 'uri'
require 'net/http'

class Article < Content
  include PublifyGuid
  include ConfigManager

  serialize :settings, Hash

  content_fields :body, :extended

  validates :guid, uniqueness: true
  validates :title, presence: true

  has_many :pings, -> { order('created_at ASC') }, dependent: :destroy
  has_many :trackbacks, -> { order('created_at ASC') }, dependent: :destroy
  has_many :feedback, -> { order('created_at DESC') }
  has_many :resources, -> { order('created_at DESC') }, dependent: :nullify
  has_many :triggers, as: :pending_item
  has_many :comments, -> { order('created_at ASC') }, dependent: :destroy

  has_many :published_comments, -> { where(published: true).order('created_at ASC') }, class_name: 'Comment'
  has_many :published_trackbacks, -> { where(published: true).order('created_at ASC') }, class_name: 'Trackback'
  has_many :published_feedback, -> { where(published: true).order('created_at ASC') }, class_name: 'Feedback'

  has_and_belongs_to_many :tags, join_table: 'articles_tags'

  before_create :create_guid
  before_save :set_published_at, :set_permalink
  after_save :post_trigger, :keywords_to_tags, :shorten_url

  scope :drafts, -> { where(state: 'draft').order('created_at DESC') }
  scope :child_of, ->(article_id) { where(parent_id: article_id) }
  scope :published_at, ->(time_params) { published.where(published_at: PublifyTime.delta(*time_params)).order('published_at DESC') }
  scope :published_since, ->(time) { published.where('published_at > ?', time).order('published_at DESC') }
  scope :withdrawn, -> { where(state: 'withdrawn').order('published_at DESC') }
  scope :pending, -> { where('state = ? and published_at > ?', 'publication_pending', Time.now).order('published_at DESC') }

  scope :bestof, lambda {
    joins(:feedback).
{'fraction_non_alphanumeric': 0.14249428498856997, 'fraction_numerical': 0.000508001016002032, 'mean_word_length': 5.341384863123993, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '5177261', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1258, 'n_words': 295}