method
compute_cache_version
v6.1.3.1 -
Show latest stable
-
0 notes -
Class: ActiveRecord::Relation
- 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
- 5.1.7
- 5.2.3
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
compute_cache_version(timestamp_column)
private
Hide source
# File activerecord/lib/active_record/relation.rb, line 344 def compute_cache_version(timestamp_column) # :nodoc: timestamp_column = timestamp_column.to_s if loaded? || distinct_value size = records.size if size > 0 timestamp = records.map { |record| record.read_attribute(timestamp_column) }.max end else collection = eager_loading? ? apply_join_dependency : self column = connection.visitor.compile(table[timestamp_column]) select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp" if collection.has_limit_or_offset? query = collection.select("#{column} AS collection_cache_key_timestamp") subquery_alias = "subquery_for_cache_key" subquery_column = "#{subquery_alias}.collection_cache_key_timestamp" arel = query.build_subquery(subquery_alias, select_values % subquery_column) else query = collection.unscope(:order) query.select_values = [select_values % column] arel = query.arel end size, timestamp = connection.select_rows(arel, nil).first if size column_type = klass.type_for_attribute(timestamp_column) timestamp = column_type.deserialize(timestamp) else size = 0 end end if timestamp "#{size}-#{timestamp.utc.to_s(cache_timestamp_format)}" else "#{size}" end end