<commit_before>require 'bcrypt'

class User < ActiveRecord::Base
  include BCrypt

  has_one :device

  delegate :device_id, :device_type, :to => :device

  def self.hash_password_for_private_key(password, sha_klass = OpenSSL::Digest::SHA256)
    sha256 = sha_klass.new

    1000.times.inject(password) do |hash, _|
      sha256.hexdigest(hash)
    end
  end

  def self.with_hashed_phone_numbers(phone_numbers)
    where("md5(phone) in (?)", phone_numbers)
  end

  def self.excluding_friends(user)
    where("id not in (?)", FriendService.find_friends(user).map(&:id))
  end

  def password
    @password ||= <PASSWORD>(<PASSWORD>)
  end

  def password=(<PASSWORD>)
    @password = <PASSWORD>(<PASSWORD>)
    self.password_hash = @password
  end

  def device_destroy
    if device
      device.destroy
      self.device = nil
    end
  end
end<commit_msg>Return an empty scope when user has no friends<commit_after>require 'bcrypt'

class User < ActiveRecord::Base
  include BCrypt

  has_one :device

  delegate :device_id, :device_type, :to => :device

  def self.hash_password_for_private_key(password, sha_klass = OpenSSL::Digest::SHA256)
    sha256 = sha_klass.new

    1000.times.inject(password) do |hash, _|
      sha256.hexdigest(hash)
    end
  end

  def self.with_hashed_phone_numbers(phone_numbers)
    where("md5(phone) in (?)", phone_numbers)
  end

  def self.excluding_friends(user)
    users = FriendService.find_friends(user)
    if users.present?
      where("id not in (?)", users.map(&:id))
    else
      scoped
    end
  end

  def password
    @password ||= <PASSWORD>(<PASSWORD>)
  end

  def password=(new_password)
    @password = <PASSWORD>(<PASSWORD>)
    self.password_hash = @password
  end

  def device_destroy
    if device
      device.destroy
      self.device = nil
    end
  end
end
{'fraction_non_alphanumeric': 0.10904109589041096, 'fraction_numerical': 0.015342465753424657, 'mean_word_length': 3.51980198019802, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '7346445', 'n_tokens_mistral': 656, 'n_tokens_neox': 609, 'n_words': 136}