FIX: Preload readonly mode attribute seperately.

There are two problems I'm trying to tackle here.

1. The site json is cached for anonymous users so readonly mode can be
cached for up to 30 minutes which makes it confusing.

2. We've already checked for readonly mode in the controller so having
to check for readonly mode again in `SiteSerializer` is adding an extra
Redis query on every request.
This commit is contained in:
Guo Xiang Tan 2020-06-12 09:54:05 +08:00
parent 2e2dcb7d93
commit 62ad473716
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
3 changed files with 4 additions and 6 deletions

View File

@ -132,7 +132,9 @@ Site.reopenClass(Singleton, {
// The current singleton will retrieve its attributes from the `PreloadStore`.
createCurrent() {
const store = Discourse.__container__.lookup("service:store");
return store.createRecord("site", PreloadStore.get("site"));
const siteAttributes = PreloadStore.get("site");
siteAttributes["isReadOnly"] = PreloadStore.get("isReadOnly");
return store.createRecord("site", siteAttributes);
},
create() {

View File

@ -539,6 +539,7 @@ class ApplicationController < ActionController::Base
store_preloaded("customHTML", custom_html_json)
store_preloaded("banner", banner_json)
store_preloaded("customEmoji", custom_emoji)
store_preloaded("isReadOnly", @readonly_mode.to_s)
end
def preload_current_user_data

View File

@ -12,7 +12,6 @@ class SiteSerializer < ApplicationSerializer
:top_menu_items,
:anonymous_top_menu_items,
:uncategorized_category_id, # this is hidden so putting it here
:is_readonly,
:disabled_plugins,
:user_field_max_length,
:post_action_types,
@ -95,10 +94,6 @@ class SiteSerializer < ApplicationSerializer
SiteSetting.uncategorized_category_id
end
def is_readonly
Discourse.readonly_mode?
end
def disabled_plugins
Discourse.disabled_plugin_names
end