<commit_before>class PageUnlockPromoCode < ApplicationRecord
  has_many :promotions
  has_many :users, -> { distinct }, through: :promotions

  def unlocked_page_types
    page_types.split('|') & Rails.application.config.content_types[:all].map(&:name)
  end


  def activate!(user)
    return false unless uses_remaining > 0

    # Make sure this user hasn't activated this promo code before
    return false unless user.present?
    return false if users.pluck(:id).include?(user.id)

    # Activate!
    # technically two requests at the same time could still double-activate at 
    # 1 use left, but this seems not worth it to fix
    update(uses_remaining: uses_remaining - 1)
  
    unlocked_page_types.each do |page_type|
      promotions.create(
        user:         user,
        content_type: page_type,
        expires_at:   DateTime.current + days_active.days,
      )
    end

    return true
  end
end
<commit_msg>@streed is the literal best<commit_after>class PageUnlockPromoCode < ApplicationRecord
  has_many :promotions
  has_many :users, -> { distinct }, through: :promotions

  serialize :page_types, Array

  def whitelisted_page_types
    page_types & Rails.application.config.content_types[:all].map(&:name)
  end


  def activate!(user)
    return false unless uses_remaining > 0

    # Make sure this user hasn't activated this promo code before
    return false unless user.present?
    return false if users.pluck(:id).include?(user.id)

    # Activate!
    # technically two requests at the same time could still double-activate at 
    # 1 use left, but this seems not worth it to fix
    update(uses_remaining: uses_remaining - 1)
  
    whitelisted_page_types.each do |page_type|
      promotions.create(
        user:         user,
        content_type: page_type,
        expires_at:   DateTime.current + days_active.days,
      )
    end

    return true
  end
end

{'fraction_non_alphanumeric': 0.07627564439768543, 'fraction_numerical': 0.003156233561283535, 'mean_word_length': 3.0991379310344827, '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': '664434', 'n_tokens_mistral': 584, 'n_tokens_neox': 555, 'n_words': 171}