method
compute_cache_version
v6.0.0 -
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 345 def compute_cache_version(timestamp_column) # :nodoc: if loaded? || distinct_value size = records.size if size > 0 timestamp = max_by(×tamp_column)._read_attribute(timestamp_column) end else collection = eager_loading? ? apply_join_dependency : self column = connection.visitor.compile(arel_attribute(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 result = connection.select_one(arel, nil) if result column_type = klass.type_for_attribute(timestamp_column) timestamp = column_type.deserialize(result["timestamp"]) size = result["size"] else timestamp = nil size = 0 end end if timestamp "#{size}-#{timestamp.utc.to_s(cache_timestamp_format)}" else "#{size}" end end