<commit_before>module IdentityCache
  module CacheKeyGeneration
    extend ActiveSupport::Concern

    def self.schema_to_string(columns)
      columns.sort_by(&:name).map{|c| "#{c.name}:#{c.type}"}.join(',')
    end

    def self.denormalized_schema_hash(klass)
      schema_string = schema_to_string(klass.columns)
      if !(associations = embedded_associations(klass)).empty?
        embedded_schema = associations.map do |name, options|
          "#{name}:(#{denormalized_schema_hash(options[:association_class])})"
        end.sort.join(',')
        schema_string << "," << embedded_schema
      end
    end

    def self.embedded_associations(klass)
      if klass.respond_to?(:all_cached_associations_needing_population)
        klass.all_cached_associations_needing_population
      else
        {}
      end
    end

    module ClassMethods
      def rails_cache_key(id)
        rails_cache_key_prefix + id.to_s
      end

      def rails_cache_key_prefix
        @rails_cache_key_prefix ||= begin
          "IDC:blob:#{base_class.name}:#{IdentityCache::CacheKeyGeneration.denormalized_schema_hash(self)}:"
        end<commit_msg>Fix premature commit and merge where I was missing a line, sorry!!<commit_after>module IdentityCache
  module CacheKeyGeneration
    extend ActiveSupport::Concern

    def self.schema_to_string(columns)
      columns.sort_by(&:name).map{|c| "#{c.name}:#{c.type}"}.join(',')
    end

    def self.denormalized_schema_hash(klass)
      schema_string = schema_to_string(klass.columns)
      if !(associations = embedded_associations(klass)).empty?
        embedded_schema = associations.map do |name, options|
          "#{name}:(#{denormalized_schema_hash(options[:association_class])})"
        end.sort.join(',')
        schema_string << "," << embedded_schema
      end
      IdentityCache.memcache_hash(schema_string)
    end

    def self.embedded_associations(klass)
      if klass.respond_to?(:all_cached_associations_needing_population)
        klass.all_cached_associations_needing_population
      else
        {}
      end
    end

    module ClassMethods
      def rails_cache_key(id)
        rails_cache_key_prefix + id.to_s
      end

      def rails_cache_key_prefix
        @rails_cache_key_prefix ||= begin
          "IDC:blob:#{base_class.name}:#{IdentityCache::CacheKeyGeneration.denormalized_schema_hash(self)}:"
        end
{'fraction_non_alphanumeric': 0.10495382031905962, 'fraction_numerical': 0.0, 'mean_word_length': 3.429368029739777, 'pattern_counts': {'":': 0, '<': 11, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7546673', 'n_tokens_mistral': 739, 'n_tokens_neox': 731, 'n_words': 111}