<commit_before>class Monologue::PostsSweeper < ActionController::Caching::Sweeper
  observe Monologue::Post


  def sweep(post)
    root_path = Monologue::Engine.routes.url_helpers.root_path if root_path.nil? # TODO: why do I have to do this to make tests pass? There must be something much more clean to make tests pass
    page_cache_directory = Rails.public_path if page_cache_directory.nil? # TODO: we should not need this either...
    if post.posts_revisions.count > 0
      current_post_path = "#{page_cache_directory}#{post.just_the_revision_one_before.url}.html" unless post.just_the_revision_one_before.nil?
      current_post_path = "#{page_cache_directory}#{post.posts_revisions.last.url}.html" if post.posts_revisions.count == 1
      File.delete current_post_path if File.exists? current_post_path
    end

    feed_file_path = "#{page_cache_directory}#{root_path}feed.rss"
    File.delete feed_file_path if File.exists? feed_file_path

    root_file_path = "#{page_cache_directory}#{root_path.chomp("/")}.html"
    File.delete root_file_path if File.exists? root_file_path

    FileUtils.rm_rf "#{page_cache_directory}/page" # remove pages
  end

  alias_method :after_create, :sweep
  alias_method :after_update, :sweep 
  alias_method :after_destroy, :sweep

end<commit_msg>now delete index.html if monologue is mounted at root<commit_after>class Monologue::PostsSweeper < ActionController::Caching::Sweeper
  observe Monologue::Post


  def sweep(post)
    root_path = Monologue::Engine.routes.url_helpers.root_path if root_path.nil? # TODO: why do I have to do this to make tests pass? There must be something much more clean to make tests pass
    page_cache_directory = Rails.public_path if page_cache_directory.nil? # TODO: we should not need this either...
    if post.posts_revisions.count > 0
      current_post_path = "#{page_cache_directory}#{post.just_the_revision_one_before.url}.html" unless post.just_the_revision_one_before.nil?
      current_post_path = "#{page_cache_directory}#{post.posts_revisions.last.url}.html" if post.posts_revisions.count == 1
      File.delete current_post_path if File.exists? current_post_path
    end

    feed_file_path = "#{page_cache_directory}#{root_path}feed.rss"
    File.delete feed_file_path if File.exists? feed_file_path

    root_file_path = "#{page_cache_directory}#{root_path.chomp("/")}.html"
    root_file_path = "#{page_cache_directory}/index.html" if root_path.chomp("/") == "" # TODO: add test for that? It would need another dummy app mounted at root...?
    File.delete root_file_path if File.exists? root_file_path

    FileUtils.rm_rf "#{page_cache_directory}/page" # remove pages
  end

  alias_method :after_create, :sweep
  alias_method :after_update, :sweep 
  alias_method :after_destroy, :sweep

end
{'fraction_non_alphanumeric': 0.09609178917174614, 'fraction_numerical': 0.0014342058085335247, 'mean_word_length': 5.0, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5614605', 'n_tokens_mistral': 925, 'n_tokens_neox': 904, 'n_words': 209}