<commit_before>class Subscription < ApplicationRecord
  self.inheritance_column = 'sti_type'

  include CommunityRelated

  belongs_to :user

  validates :type, presence: true, inclusion: ['all', 'tag', 'user', 'interesting']
  validates :frequency, numericality: { minimum: 1, maximum: 90 }

  validate :qualifier_presence

  def questions
    case type
    when 'all'
      Question.unscoped.where(community: community).where('created_at >= ?', last_sent_at)
    when 'tag'
      Tag.unscoped.where(community: community).find_by(name: qualifier)&.posts&.unscoped&.where(community: community)
    when 'user'
      User.find_by(id: qualifier)&.questions&.unscoped&.where(community: community)
    when 'interesting'
      Question.unscoped.where(community: community)
              .where('score >= ?', SiteSetting['InterestingSubscriptionScoreThreshold'])
              .order(Arel.sql('RAND()'))
    end&.order(created_at: :desc)&.limit(100)
  end

  private
<commit_msg>Properly de-scope subscriptions<commit_after>class Subscription < ApplicationRecord
  self.inheritance_column = 'sti_type'

  include CommunityRelated

  belongs_to :user

  validates :type, presence: true, inclusion: ['all', 'tag', 'user', 'interesting']
  validates :frequency, numericality: { minimum: 1, maximum: 90 }

  validate :qualifier_presence

  def questions
    case type
    when 'all'
      Question.unscoped.where(community: community, post_type_id: Question.post_type_id)
              .where('created_at >= ?', last_sent_at)
    when 'tag'
      Question.unscoped.where(community: community, post_type_id: Question.post_type_id)
              .joins(:tags).where(tags: { name: qualifier })
    when 'user'
      Question.unscoped.where(community: community, post_type_id: Question.post_type_id)
              .where(user_id: qualifier)
    when 'interesting'
      Question.unscoped.where(community: community, post_type_id: Question.post_type_id)
              .where('score >= ?', SiteSetting['InterestingSubscriptionScoreThreshold'])
              .order(Arel.sql('RAND()'))
    end&.order(created_at: :desc)&.limit(25)
  end

  private

{'fraction_non_alphanumeric': 0.1224202626641651, 'fraction_numerical': 0.005159474671669793, 'mean_word_length': 3.914746543778802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6169756', 'n_tokens_mistral': 682, 'n_tokens_neox': 644, 'n_words': 129}