From 860a34da902f67d98736d99c620cb407e60e1edb Mon Sep 17 00:00:00 2001 From: zanetagebka Date: Mon, 20 Jul 2026 13:35:46 +0200 Subject: [PATCH 1/2] after request locale resolution --- .../folio/application_controller_base.rb | 5 +++++ .../folio/set_current_request_details.rb | 13 +++++++++++- app/models/folio/current.rb | 20 ++++++++++--------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/controllers/concerns/folio/application_controller_base.rb b/app/controllers/concerns/folio/application_controller_base.rb index 1cd5cfd8cd..4ef8317563 100644 --- a/app/controllers/concerns/folio/application_controller_base.rb +++ b/app/controllers/concerns/folio/application_controller_base.rb @@ -16,6 +16,7 @@ module Folio::ApplicationControllerBase layout :current_site_based_layout before_action :set_i18n_locale + before_action :set_folio_current_cache_key_base before_action :set_cookies_for_log @@ -36,6 +37,10 @@ def set_i18n_locale end end + def set_folio_current_cache_key_base + Folio::Current.cache_key_base = Rails.application.config.action_controller.perform_caching ? try(:cache_key_base) : nil + end + def default_url_options { only_path: true } end diff --git a/app/controllers/concerns/folio/set_current_request_details.rb b/app/controllers/concerns/folio/set_current_request_details.rb index cf0045d5f7..845b2c7488 100644 --- a/app/controllers/concerns/folio/set_current_request_details.rb +++ b/app/controllers/concerns/folio/set_current_request_details.rb @@ -20,7 +20,18 @@ def set_up_current_from_request Folio::Current.setup!(request:, user: current_user, session:, - cache_key_base: Rails.application.config.action_controller.perform_caching ? try(:cache_key_base) : nil) + site_cache_key_base: Rails.application.config.action_controller.perform_caching ? folio_current_site_cache_key_base : nil) + end + end + + def folio_current_site_cache_key_base + @folio_current_site_cache_key_base ||= Rails.cache.fetch(["Folio::Current.site_cache_key_base", request.host], expires_in: 30.seconds) do + [ + ENV["CURRENT_RELEASE_COMMIT_HASH"], + request.host, + Folio::Site.maximum(:updated_at)&.to_f, + Folio::Site.count, + ] end end end diff --git a/app/models/folio/current.rb b/app/models/folio/current.rb index 92143dd976..03a97022f8 100644 --- a/app/models/folio/current.rb +++ b/app/models/folio/current.rb @@ -14,6 +14,7 @@ class Folio::Current < ActiveSupport::CurrentAttributes :session, :ability, :cache_key_base, + :site_cache_key_base, :skip_caching SITE_KEYS = %i[ @@ -27,11 +28,11 @@ def to_h attributes end - def setup!(request:, user: nil, session: nil, cache_key_base: nil) - setup_folio_data(request:, user:, session:, cache_key_base:) + def setup!(request:, user: nil, session: nil, cache_key_base: nil, site_cache_key_base: cache_key_base) + setup_folio_data(request:, user:, session:, cache_key_base:, site_cache_key_base:) end - def setup_folio_data(request:, user:, session:, cache_key_base:) + def setup_folio_data(request:, user:, session:, cache_key_base:, site_cache_key_base:) self.host = request.host self.request_id = request.uuid self.user_agent = request.user_agent @@ -41,8 +42,9 @@ def setup_folio_data(request:, user:, session:, cache_key_base:) self.session = session self.cache_key_base = cache_key_base + self.site_cache_key_base = site_cache_key_base - # keep the code that uses site under cache_key_base + # keep the code that uses site under site_cache_key_base nillify_site_records unless self.class.site_matches_host?(site:, host:) self.ability = Folio::Ability.new(user, site) end @@ -68,9 +70,9 @@ def self.site_matches_host?(site:, host:) end def self.cache_aware_get_site(host: nil) - if !skip_caching && cache_key_base - # cache_key_base should contain request.host - Rails.cache.fetch(["Folio::Current.cache_aware_get_site"] + cache_key_base, expires_in: Folio.expires_in) do + if !skip_caching && site_cache_key_base + # site_cache_key_base should contain request.host + Rails.cache.fetch(["Folio::Current.cache_aware_get_site"] + site_cache_key_base, expires_in: Folio.expires_in) do get_site(host:) end else @@ -101,8 +103,8 @@ def site end def self.cache_aware_get_main_site - if !skip_caching && cache_key_base - Rails.cache.fetch(["Folio::Current.cache_aware_get_main_site"] + cache_key_base, expires_in: Folio.expires_in) do + if !skip_caching && site_cache_key_base + Rails.cache.fetch(["Folio::Current.cache_aware_get_main_site"] + site_cache_key_base, expires_in: Folio.expires_in) do get_main_site end else From d1c3bffceb5d6630b4323286545543bd81a156f1 Mon Sep 17 00:00:00 2001 From: zanetagebka Date: Mon, 20 Jul 2026 13:36:01 +0200 Subject: [PATCH 2/2] after request locale resolution - changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc29f23547..cbd785a50a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ All notable changes to this project will be documented in this file. - default `devise_modules` moved to folio config, so each app can set their own set. Default are `%i[database_authenticatable recoverable rememberable trackable invitable timeoutable lockable] - added option `Rails.application.config.folio_cookie_consent_configuration[:keep_attached_after_accept]` (default false). Set it `true` if app allways display link to open cookies settings. +### Fixed + +- set `Folio::Current.cache_key_base` only after request locale resolution and use a locale-independent cache key for current site lookup + ## [6.5.1] - 2025-06-18 ### Added