A platform for community discussion. Free, open, simple.
FIX: Include locale in cache key for not_found_topics (#11406)
David Taylor8b33e2f73ddd
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex a1fc32cf768..53878b0396b 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -803,16 +803,13 @@ class ApplicationController < ActionController::Base@current_user = current_user rescue nilif !SiteSetting.login_required? || @current_user- key = "page_not_found_topics"- if @topics_partial = Discourse.redis.get(key)- @topics_partial = @topics_partial.html_safe- else+ key = "page_not_found_topics:#{I18n.locale}"+ @topics_partial = Discourse.cache.fetch(key, expires_in: 10.minutes) docategory_topic_ids = Category.pluck(:topic_id).compact@top_viewed = TopicQuery.new(nil, except_topic_ids: category_topic_ids).list_top_for("monthly").topics.first(10)@recent = Topic.includes(:category).where.not(id: category_topic_ids).recent(10)- @topics_partial = render_to_string partial: '/exceptions/not_found_topics', formats: [:html]- Discourse.redis.setex(key, 10.minutes, @topics_partial)- end+ render_to_string partial: '/exceptions/not_found_topics', formats: [:html]+ end.html_safeend@container_class = "wrap not-found-container"diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rbindex 7808d23de2c..5e82551fc2b 100644--- a/spec/requests/application_controller_spec.rb+++ b/spec/requests/application_controller_spec.rb@@ -373,7 +373,7 @@ RSpec.describe ApplicationController doit 'should handle 404 to a css file' do- Discourse.redis.del("page_not_found_topics")+ Discourse.cache.delete("page_not_found_topics:#{I18n.locale}")topic1 = Fabricate(:topic)get '/stylesheets/mobile_1_4cd559272273fe6d3c7db620c617d596a5fdf240.css', headers: { 'HTTP_ACCEPT' => 'text/css,*/*,q=0.1' }@@ -394,7 +394,8 @@ RSpec.describe ApplicationController doendit 'should cache results' do- Discourse.redis.del("page_not_found_topics")+ Discourse.cache.delete("page_not_found_topics:#{I18n.locale}")+ Discourse.cache.delete("page_not_found_topics:fr")topic1 = Fabricate(:topic)get '/t/nope-nope/99999999'@@ -406,6 +407,13 @@ RSpec.describe ApplicationController doexpect(response.status).to eq(404)expect(response.body).to include(topic1.title)expect(response.body).to_not include(topic2.title)++ # Different locale should have different cache+ SiteSetting.default_locale = :fr+ get '/t/nope-nope/99999999'+ expect(response.status).to eq(404)+ expect(response.body).to include(topic1.title)+ expect(response.body).to include(topic2.title)endendend