method
collection_cache_key

v5.0.0.1 -
Show latest stable
-
0 notes -
Class: CollectionCacheKey
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
collection_cache_key(collection = all, timestamp_column = :updated_at)
public
Hide source
# File activerecord/lib/active_record/collection_cache_key.rb, line 4 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 if size > 0 timestamp = collection.max_by(×tamp_column).public_send(timestamp_column) end 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 .unscope(:select) .select("COUNT(*) AS #{connection.quote_column_name("size")}", "MAX(#{column}) AS timestamp") .unscope(:order) result = connection.select_one(query) if result.blank? size = 0 timestamp = nil else size = result["size"] timestamp = column_type.deserialize(result["timestamp"]) end end if timestamp "#{key}-#{size}-#{timestamp.utc.to_s(cache_timestamp_format)}" else "#{key}-#{size}" end end