mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 20:46:18 +08:00
FIX: Clear uploads cache on SiteSetting.refresh!
.
This fixes a bug where the return value of uploads site settings may defer between processes even though we trigger a refresh via MessageBus.
This commit is contained in:
parent
9e86b425bc
commit
0ac5126a78
|
@ -269,8 +269,16 @@ module SiteSettingExtension
|
||||||
shadowed_settings.each { |ss| new_hash[ss] = GlobalSetting.send(ss) }
|
shadowed_settings.each { |ss| new_hash[ss] = GlobalSetting.send(ss) }
|
||||||
|
|
||||||
changes, deletions = diff_hash(new_hash, current)
|
changes, deletions = diff_hash(new_hash, current)
|
||||||
changes.each { |name, val| current[name] = val }
|
|
||||||
deletions.each { |name, _| current[name] = defaults_view[name] }
|
changes.each do |name, val|
|
||||||
|
current[name] = val
|
||||||
|
clear_uploads_cache(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
deletions.each do |name, _|
|
||||||
|
current[name] = defaults_view[name]
|
||||||
|
clear_uploads_cache(name)
|
||||||
|
end
|
||||||
|
|
||||||
clear_cache!
|
clear_cache!
|
||||||
end
|
end
|
||||||
|
@ -318,7 +326,7 @@ module SiteSettingExtension
|
||||||
def remove_override!(name)
|
def remove_override!(name)
|
||||||
provider.destroy(name)
|
provider.destroy(name)
|
||||||
current[name] = defaults.get(name, default_locale)
|
current[name] = defaults.get(name, default_locale)
|
||||||
uploads.delete(name)
|
clear_uploads_cache(name)
|
||||||
clear_cache!
|
clear_cache!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -326,7 +334,7 @@ module SiteSettingExtension
|
||||||
val, type = type_supervisor.to_db_value(name, val)
|
val, type = type_supervisor.to_db_value(name, val)
|
||||||
provider.save(name, val, type)
|
provider.save(name, val, type)
|
||||||
current[name] = type_supervisor.to_rb_value(name, val)
|
current[name] = type_supervisor.to_rb_value(name, val)
|
||||||
uploads.delete(name)
|
clear_uploads_cache(name)
|
||||||
notify_clients!(name) if client_settings.include? name
|
notify_clients!(name) if client_settings.include? name
|
||||||
clear_cache!
|
clear_cache!
|
||||||
end
|
end
|
||||||
|
@ -480,6 +488,12 @@ module SiteSettingExtension
|
||||||
@uploads[provider.current_site] ||= {}
|
@uploads[provider.current_site] ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_uploads_cache(name)
|
||||||
|
if type_supervisor.get_type(name) == :upload && uploads.has_key?(name)
|
||||||
|
uploads.delete(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def logger
|
def logger
|
||||||
Rails.logger
|
Rails.logger
|
||||||
end
|
end
|
||||||
|
|
|
@ -133,6 +133,24 @@ describe SiteSettingExtension do
|
||||||
settings.foo = "baz"
|
settings.foo = "baz"
|
||||||
expect(settings.foo).to eq("baz")
|
expect(settings.foo).to eq("baz")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "clears the cache for site setting uploads" do
|
||||||
|
settings.setting(:upload_type, "", type: :upload)
|
||||||
|
upload = Fabricate(:upload)
|
||||||
|
settings.upload_type = upload
|
||||||
|
|
||||||
|
expect(settings.upload_type).to eq(upload)
|
||||||
|
expect(settings.send(:uploads)[:upload_type]).to eq(upload)
|
||||||
|
|
||||||
|
upload2 = Fabricate(:upload)
|
||||||
|
settings.provider.save(:upload_type, upload2.id, SiteSetting.types[:upload])
|
||||||
|
|
||||||
|
expect do
|
||||||
|
settings.refresh!
|
||||||
|
end.to change { settings.send(:uploads)[:upload_type] }.from(upload).to(nil)
|
||||||
|
|
||||||
|
expect(settings.upload_type).to eq(upload2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "multisite" do
|
describe "multisite" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user