<commit_before>namespace :stories do

  desc "Republish stories to redis"
  task :republish => :environment do
    NewsFeed.delete_all
    Story.includes(:actors, :activities).find_each do |story|
      puts "story: #{story.id} #{story.verb.rjust(15)} #{story.subject_type}"

      story.reader_ids.each do |user_id|
        NewsFeed.new(User, user_id).push(story)
      end
    end
  end

  desc "Remove stories with orphaned targets"
  task prune: :environment do
    count = 0
    Story.includes(:activities).find_each do |story|
      if story.activities.empty?
        puts "destroying: #{story.id}"
        story.destroy
        count += 1
      end
    end
    puts "destroyed #{count} stories"
  end
end
<commit_msg>Add task to regroup stories<commit_after>namespace :stories do

  desc "Republish stories to redis"
  task :republish => :environment do
    NewsFeed.delete_all
    Story.includes(:actors, :activities).find_each do |story|
      puts "story: #{story.id} #{story.verb.rjust(15)} #{story.subject_type}"

      story.reader_ids.each do |user_id|
        NewsFeed.new(User, user_id).push(story)
      end
    end
  end

  desc "Remove stories with orphaned targets"
  task prune: :environment do
    count = 0
    Story.includes(:activities).find_each do |story|
      if story.activities.empty?
        puts "destroying: #{story.id}"
        story.destroy
        count += 1
      end
    end
    puts "destroyed #{count} stories"
  end

  desc "Regroup stories by actors"
  task regroup: :environment do
    RegroupStories.new.perform(1.day.ago)
  end
end

{'fraction_non_alphanumeric': 0.10646387832699619, 'fraction_numerical': 0.005703422053231939, 'mean_word_length': 2.9181141439205955, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5073024', 'n_tokens_mistral': 518, 'n_tokens_neox': 508, 'n_words': 137}