<commit_before>module WhoToBlame
  class DatabaseManager
    def stats
      file_types = FileType.includes(footprints: :author).all
      file_types.each_with_object({}) do |file_type, memo|
        memo[file_type.name] = lines_per_author(file_type)
      end
    end

    def clear!
      Footprint.destroy_all
      Author.destroy_all
      FileType.destroy_all
      self
    end

    # Stats should be a hash from file_type => lines_per_author
    def load!(stats)<commit_msg>Fixing N+1 query<commit_after>module WhoToBlame
  class DatabaseManager
    def stats
      file_types = FileType.includes(footprints: :author).all
      file_types.each_with_object({}) do |file_type, memo|
        memo[file_type.name] = lines_per_author(file_type)
      end
    end

    def clear!
      Footprint.destroy_all
      Author.includes(:footprints).destroy_all
      FileType.includes(:footprints).destroy_all
      self
    end

    # Stats should be a hash from file_type => lines_per_author
    def load!(stats)
{'fraction_non_alphanumeric': 0.07631318136769079, 'fraction_numerical': 0.0009910802775024777, 'mean_word_length': 3.0562248995983934, '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': '3421804', 'n_tokens_mistral': 316, 'n_tokens_neox': 308, 'n_words': 69}