FIX: Invalidate site settings cache in all instances (#16155)

Previous cache implementation did not support multisite instances and
the cache was invalidated only in the instance where the change took
place.
This commit is contained in:
Bianca Nenciu 2022-03-11 17:16:56 +02:00 committed by GitHub
parent 94750c81fa
commit 7a416257df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 14 deletions

View File

@ -101,23 +101,33 @@ class SiteSetting < ActiveRecord::Base
:markdown_typographer_quotation_marks
]
def self.reset_cached_settings!
@blocked_attachment_content_types_regex = nil
@blocked_attachment_filenames_regex = nil
@allowed_unicode_username_regex = nil
end
def self.blocked_attachment_content_types_regex
@blocked_attachment_content_types_regex ||= Regexp.union(SiteSetting.blocked_attachment_content_types.split("|"))
current_db = RailsMultisite::ConnectionManagement.current_db
@blocked_attachment_content_types_regex ||= {}
@blocked_attachment_content_types_regex[current_db] ||= begin
Regexp.union(SiteSetting.blocked_attachment_content_types.split("|"))
end
end
def self.blocked_attachment_filenames_regex
@blocked_attachment_filenames_regex ||= Regexp.union(SiteSetting.blocked_attachment_filenames.split("|"))
current_db = RailsMultisite::ConnectionManagement.current_db
@blocked_attachment_filenames_regex ||= {}
@blocked_attachment_filenames_regex[current_db] ||= begin
Regexp.union(SiteSetting.blocked_attachment_filenames.split("|"))
end
end
def self.allowed_unicode_username_characters_regex
@allowed_unicode_username_regex ||= SiteSetting.allowed_unicode_username_characters.present? \
? Regexp.new(SiteSetting.allowed_unicode_username_characters) : nil
current_db = RailsMultisite::ConnectionManagement.current_db
@allowed_unicode_username_regex ||= {}
@allowed_unicode_username_regex[current_db] ||= begin
if SiteSetting.allowed_unicode_username_characters.present?
Regexp.new(SiteSetting.allowed_unicode_username_characters)
end
end
end
# helpers for getting s3 settings that fallback to global
@ -246,6 +256,16 @@ class SiteSetting < ActiveRecord::Base
send("#{new_method}=", args)
end
end
protected
def self.clear_cache!
super
@blocked_attachment_content_types_regex = nil
@blocked_attachment_filenames_regex = nil
@allowed_unicode_username_regex = nil
end
end
# == Schema Information

View File

@ -45,10 +45,6 @@ DiscourseEvent.on(:site_setting_changed) do |name, old_value, new_value|
SiteIconManager.ensure_optimized!
end
if SiteSetting::WATCHED_SETTINGS.include?(name)
SiteSetting.reset_cached_settings!
end
# Make sure medium and high priority thresholds were calculated.
if name == :reviewable_low_priority_threshold && Reviewable.min_score_for_priority(:medium) > 0
Reviewable.set_priorities(low: new_value)