Flowdock
method

compute_cache_version

Importance_0
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.2
  • 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)
  • What's this?
compute_cache_version(timestamp_column) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

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(&timestamp_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
Register or log in to add new notes.