<commit_before>module ActiveRecord
  module CollectionCacheKey

    def collection_cache_key(collection = all, timestamp_column = :updated_at) # :nodoc:
      query_signature = Digest::MD5.hexdigest(collection.to_sql)
      key = "#{collection.model_name.cache_key}/query-#{query_signature}"

      if collection.loaded?
        size = collection.size
        timestamp = collection.max_by(&timestamp_column).public_send(timestamp_column)
      else
        column_type = type_for_attribute(timestamp_column.to_s)
        column = "#{connection.quote_table_name(collection.table_name)}.#{connection.quote_column_name(timestamp_column)}"

        query = collection.select("COUNT(*) AS size", "MAX(#{column}) AS timestamp")
        result = connection.select_one(query)
<commit_msg>Fix test failures caused by #20884<commit_after>module ActiveRecord
  module CollectionCacheKey

    def collection_cache_key(collection = all, timestamp_column = :updated_at) # :nodoc:
      query_signature = Digest::MD5.hexdigest(collection.to_sql)
      key = "#{collection.model_name.cache_key}/query-#{query_signature}"

      if collection.loaded?
        size = collection.size
        timestamp = collection.max_by(&timestamp_column).public_send(timestamp_column)
      else
        column_type = type_for_attribute(timestamp_column.to_s)
        column = "#{connection.quote_table_name(collection.table_name)}.#{connection.quote_column_name(timestamp_column)}"

        query = collection
          .select("COUNT(*) AS size", "MAX(#{column}) AS timestamp")
          .unscope(:order)
        result = connection.select_one(query)

{'fraction_non_alphanumeric': 0.10919185687847008, 'fraction_numerical': 0.00431832202344232, 'mean_word_length': 4.14920634920635, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665504', 'n_tokens_mistral': 465, 'n_tokens_neox': 457, 'n_words': 75}