A platform for community discussion. Free, open, simple.
FIX: Vary the user summary cache by automatic translation
Régis Hanol5e9779d4cd41
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex c39d344f2b8..2929a9b1a8f 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -2362,7 +2362,13 @@ class UsersController < ApplicationControllerenddef summary_cache_key(user)- "user_summary:#{user.id}:#{current_user ? current_user.id : 0}:#{I18n.locale}"+ [+ "user_summary",+ user.id,+ current_user&.id.to_i,+ I18n.locale,+ ContentLocalization.automatically_translate?(guardian),+ ].join(":")enddef render_invite_error(message)diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex d70a2d63e0a..2f540bb9ef4 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -4734,6 +4734,22 @@ RSpec.describe UsersController douser_deferred.user_stat.update!(post_count: 1)end+ it "caches separately per automatic translation preference" do+ SiteSetting.content_localization_enabled = true+ SiteSetting.set_locale_from_accept_language_header = true+ topic = Fabricate(:topic, user: user, locale: "en")+ Fabricate(:post, topic: topic, user: user)+ Fabricate(:topic_localization, topic: topic, locale: "ja", fancy_title: "翻訳された題名")++ cookies[ContentLocalization::AUTOMATICALLY_TRANSLATE_COOKIE] = "false"+ get "/u/#{user.username_lower}/summary.json", headers: { "HTTP_ACCEPT_LANGUAGE" => "ja" }+ expect(response.parsed_body["topics"].first["fancy_title"]).to eq(topic.fancy_title)++ cookies[ContentLocalization::AUTOMATICALLY_TRANSLATE_COOKIE] = "true"+ get "/u/#{user.username_lower}/summary.json", headers: { "HTTP_ACCEPT_LANGUAGE" => "ja" }+ expect(response.parsed_body["topics"].first["fancy_title"]).to eq("翻訳された題名")+ end+it "generates summary info" docreate_post(user: user)