From a0d72938f3e495e5f7b3154f63fd04d489a9c188 Mon Sep 17 00:00:00 2001 From: GPT on behalf of DHH <2741+dhh@users.noreply.github.com> Date: Thu, 8 Oct 2026 12:40:31 +0200 Subject: [PATCH] Keep transaction guards temporary and simplify quick boost forms --- app/controllers/concerns/cached_responses.rb | 4 +-- app/models/fragment_cache.rb | 4 +++ app/models/record_cache.rb | 2 +- app/views/messages/_actions.html.erb | 11 ++++---- .../messages/boosts_controller_test.rb | 26 +++++++++++++++++++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/controllers/concerns/cached_responses.rb b/app/controllers/concerns/cached_responses.rb index 05d7be1..b17e29a 100644 --- a/app/controllers/concerns/cached_responses.rb +++ b/app/controllers/concerns/cached_responses.rb @@ -10,7 +10,7 @@ module CachedResponses end def perform_caching - return false unless super && @response_cache_version.present? && !ActiveRecord::Base.connection_pool.active_connection?&.transaction_open? + return false unless super && @response_cache_version.present? && !FragmentCache.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_pool.active_connection?&.transaction_open? + !FragmentCache.transaction_open? end def response_cache_key(encoding) diff --git a/app/models/fragment_cache.rb b/app/models/fragment_cache.rb index bb0f7e9..40147b3 100644 --- a/app/models/fragment_cache.rb +++ b/app/models/fragment_cache.rb @@ -13,4 +13,8 @@ class FragmentCache def self.store STORE end + + def self.transaction_open? + ActiveRecord::Base.connection_pool.with_connection(&:transaction_open?) + end end diff --git a/app/models/record_cache.rb b/app/models/record_cache.rb index 2446093..1db362d 100644 --- a/app/models/record_cache.rb +++ b/app/models/record_cache.rb @@ -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_pool.active_connection?&.transaction_open? + return yield unless version && ResponseCache.instance.budget.positive? && !FragmentCache.transaction_open? key = ActiveSupport::Cache.expand_cache_key([ "record-snapshot-v1", version, key ]) return yield if key.bytesize > ResponseCache::MAX_KEY_BYTES diff --git a/app/views/messages/_actions.html.erb b/app/views/messages/_actions.html.erb index 48973d6..8948783 100644 --- a/app/views/messages/_actions.html.erb +++ b/app/views/messages/_actions.html.erb @@ -12,14 +12,15 @@