Check cache transactions without leasing a database connection

This commit is contained in:
GPT on behalf of DHH
2026-10-08 12:34:18 +02:00
parent bbee420097
commit a9007010c1
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ module CachedResponses
end
def perform_caching
return false unless super && @response_cache_version.present? && !ActiveRecord::Base.connection.transaction_open?
return false unless super && @response_cache_version.present? && !ActiveRecord::Base.connection_pool.active_connection?&.transaction_open?
# Check again after authentication, before the first native fragment lookup.
# Later renders retain this immutable namespace and cannot poison a new epoch.
@@ -103,7 +103,7 @@ module CachedResponses
!authenticated_by.bot_key? && flash.empty? &&
!request.headers["If-None-Match"] && !request.headers["If-Modified-Since"] &&
!Rails.application.config.content_security_policy_nonce_generator &&
!ActiveRecord::Base.connection.transaction_open?
!ActiveRecord::Base.connection_pool.active_connection?&.transaction_open?
end
def response_cache_key(encoding)
+1 -1
View File
@@ -2,7 +2,7 @@
# The observer must still see the captured epoch after lookup and admission.
class RecordCache
def self.fetch(key, version)
return yield unless version && ResponseCache.instance.budget.positive? && !ActiveRecord::Base.connection.transaction_open?
return yield unless version && ResponseCache.instance.budget.positive? && !ActiveRecord::Base.connection_pool.active_connection?&.transaction_open?
key = ActiveSupport::Cache.expand_cache_key([ "record-snapshot-v1", version, key ])
return yield if key.bytesize > ResponseCache::MAX_KEY_BYTES