<commit_before>class User < ActiveRecord::Base
  has_many :subscriptions, dependent: :destroy
  has_many :categories, through: :subscriptions
  has_many :feeds, through: :subscriptions

  before_save :tokenize

  validates :username, :uid, :provider, presence: true

  normalize_attributes :email

  def self.from_omniauth(auth_hash)
    where(provider: auth_hash[:provider], uid: auth_hash[:uid]).first
  end

  def self.create_from_omniauth(auth_hash)
    create! do |user|
      user.provider = auth_hash[:provider]
      user.uid = auth_hash[:uid]
      user.username = auth_hash[:info][:nickname] || auth_hash[:info][:name]
      user.email = auth_hash[:info][:email]
    end
  end

  def bundled_subscriptions
    newsitems = Newsitem.latest_issues_for(subscriptions).to_ary
    subscriptions.bundled_for_navigation.each_with_object({}) do |c, p|
      p[c.category.name] ||= {
        id: c.category.id,
        feeds: []
      }
      p[c.category.name][:feeds] << {
        feed: c.feed,
        unreads: c.unreads,
        latest: newsitems.shift
      }
      p
    end
  end

  def unread_feeds
    subscriptions.includes({ entries: :newsitem }, :feed)
      .where('entries.unread' => true)
      .order('newsitems.published desc, newsitems.id desc')
  end

  private

  def tokenize
    self.token = SecureRandom.urlsafe_base64
  end
end

# == Schema Information
#
# Table name: users
#
#  id         :integer          not null, primary key
#  username   :string
#  email      :string
#  uid        :string
#  provider   :string
#  token      :string
#  created_at :datetime
#  updated_at :datetime
#
# Indexes
#
#  index_users_on_email  (email) UNIQUE
#  index_users_on_token  (token) UNIQUE
#
<commit_msg>Remove normalize_attributes usage from user email<commit_after>class User < ActiveRecord::Base
  has_many :subscriptions, dependent: :destroy
  has_many :categories, through: :subscriptions
  has_many :feeds, through: :subscriptions

  before_save :tokenize

  validates :username, :uid, :provider, presence: true

  def self.from_omniauth(auth_hash)
    where(provider: auth_hash[:provider], uid: auth_hash[:uid]).first
  end

  def self.create_from_omniauth(auth_hash)
    create! do |user|
      user.provider = auth_hash[:provider]
      user.uid = auth_hash[:uid]
      user.username = auth_hash[:info][:nickname] || auth_hash[:info][:name]
      user.email = auth_hash[:info][:email]
    end
  end

  def bundled_subscriptions
    newsitems = Newsitem.latest_issues_for(subscriptions).to_ary
    subscriptions.bundled_for_navigation.each_with_object({}) do |c, p|
      p[c.category.name] ||= {
        id: c.category.id,
        feeds: []
      }
      p[c.category.name][:feeds] << {
        feed: c.feed,
        unreads: c.unreads,
        latest: newsitems.shift
      }
      p
    end
  end

  def unread_feeds
    subscriptions.includes({ entries: :newsitem }, :feed)
      .where('entries.unread' => true)
      .order('newsitems.published desc, newsitems.id desc')
  end

  private

  def tokenize
    self.token = SecureRandom.urlsafe_base64
  end
end

# == Schema Information
#
# Table name: users
#
#  id         :integer          not null, primary key
#  username   :string
#  email      :string
#  uid        :string
#  provider   :string
#  token      :string
#  created_at :datetime
#  updated_at :datetime
#
# Indexes
#
#  index_users_on_email  (email) UNIQUE
#  index_users_on_token  (token) UNIQUE
#

{'fraction_non_alphanumeric': 0.1116913257905425, 'fraction_numerical': 0.0011604293588627793, 'mean_word_length': 3.1194743130227, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6842164', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1139, 'n_words': 247}