<commit_before>class PushNotificationSend
  include Sidekiq::Worker
  sidekiq_options retry: false, queue: :critical

  # ENV['RAILS_ENV'] = 'production'; reload!; p = PushNotificationSend.new; p.perform(1, [1])
  #
  # Payload must be less than 256 bytes a payload without the body is about
  # 157 bytes
  def perform(entry_id, user_ids)
    if $grocer
      notifications = build_notifications(entry_id, user_ids)
      send_notifications(notifications)
    end
  end

  def send_notifications(notifications)
    $grocer.with do |pusher|
      notifications.each { |notification| pusher.push(notification) }
    end
    Librato.increment 'push_notifications_sent', by: notifications.length
  end

  def build_notifications(entry_id, user_ids)
    entry = Entry.find(entry_id)
    feed = Feed.find(entry.feed_id)
    users = User.where(id: user_ids)
    verifier = ActiveSupport::MessageVerifier.new(Feedbin::Application.config.secret_key_base)

    # Use user specified feed titles where available
    titles = Subscription.where(feed: feed, user_id: user_ids).pluck(:user_id, :title).inject({}) do |hash, (user_id, feed_title)|
      hash[user_id] = feed_title
      hash
    end

    notifications = []
    users.each do |user|<commit_msg>Clean up.<commit_after>class PushNotificationSend
  include Sidekiq::Worker
  sidekiq_options retry: false, queue: :critical

  # ENV['RAILS_ENV'] = 'production'; reload!; p = PushNotificationSend.new; p.perform(1, [1])
  #
  # Payload must be less than 256 bytes a payload without the body is about
  # 157 bytes
  def perform(entry_id, user_ids)
    if $grocer
      notifications = build_notifications(entry_id, user_ids)
      send_notifications(notifications)
    end
  end

  def send_notifications(notifications)
    $grocer.with do |pusher|
      notifications.each { |notification| pusher.push(notification) }
    end
    Librato.increment 'push_notifications_sent', by: notifications.length
  end

  def build_notifications(entry_id, user_ids)
    entry = Entry.find(entry_id)
    feed = Feed.find(entry.feed_id)
    users = User.where(id: user_ids)
    verifier = ActiveSupport::MessageVerifier.new(Feedbin::Application.config.secret_key_base)

    # Use user specified feed titles where available
    titles = Subscription.where(feed: feed, user_id: user_ids).pluck(:user_id, :title)
    titles = titles.each_with_object({}) do |(user_id, feed_title), hash|
      hash[user_id] = feed_title
    end

    notifications = []
    users.each do |user|
{'fraction_non_alphanumeric': 0.09908110267678785, 'fraction_numerical': 0.006392329204954055, 'mean_word_length': 4.1416837782340865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4723139', 'n_tokens_mistral': 825, 'n_tokens_neox': 794, 'n_words': 189}