<commit_before># frozen_string_literal: true

# Allows users to start new discussion topics on the forum.
class Chapter < ActiveRecord::Base
  REPLIES_PER_PAGE = 20
  attr_accessor :description, :migration_flag

  # Concerns
  include Deletable
  include PgSearch
  multisearchable against: [:title],
                  unless: :deleted?

  # Callbacks
  after_commit :create_first_reply, on: :create

  # Named Scopes
  scope :reply_count, -> { select('chapters.*, COUNT(replies.id) reply_count').joins(:replies).group('chapters.id').distinct }

  # Model Validation
  validates :title, :slug, :user_id, presence: true
  validates :description, presence: true, if: :requires_description?
  validates :slug, uniqueness: { scope: :deleted }
  validates :slug, format: { with: /\A(?!\Anew\Z)[a-z][a-z0-9\-]*\Z/ }<commit_msg>Fixed an issue loading forum caused by missing group by clause required by PG<commit_after># frozen_string_literal: true

# Allows users to start new discussion topics on the forum.
class Chapter < ActiveRecord::Base
  REPLIES_PER_PAGE = 20
  attr_accessor :description, :migration_flag

  # Concerns
  include Deletable
  include PgSearch
  multisearchable against: [:title],
                  unless: :deleted?

  # Callbacks
  after_commit :create_first_reply, on: :create

  # Named Scopes
  # TODO: chapters.title not needed in PG 9+
  scope :reply_count, -> { select('chapters.*, COUNT(replies.id) reply_count').joins(:replies).group('chapters.id, chapters.title') }

  # Model Validation
  validates :title, :slug, :user_id, presence: true
  validates :description, presence: true, if: :requires_description?
  validates :slug, uniqueness: { scope: :deleted }
  validates :slug, format: { with: /\A(?!\Anew\Z)[a-z][a-z0-9\-]*\Z/ }
{'fraction_non_alphanumeric': 0.12116040955631399, 'fraction_numerical': 0.005119453924914676, 'mean_word_length': 4.33030303030303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2446050', 'n_tokens_mistral': 589, 'n_tokens_neox': 571, 'n_words': 155}