mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
REFACTOR: We don't cache the json for the Site model anymore, so let's
rename and remove the methods leftover from that.
This commit is contained in:
@ -215,7 +215,7 @@ class ApplicationController < ActionController::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def preload_anonymous_data
|
def preload_anonymous_data
|
||||||
store_preloaded("site", Site.cached_json(guardian))
|
store_preloaded("site", Site.json_for(guardian))
|
||||||
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
||||||
store_preloaded("customHTML", custom_html_json)
|
store_preloaded("customHTML", custom_html_json)
|
||||||
end
|
end
|
||||||
|
@ -28,11 +28,9 @@ class Category < ActiveRecord::Base
|
|||||||
validate :parent_category_validator
|
validate :parent_category_validator
|
||||||
|
|
||||||
before_validation :ensure_slug
|
before_validation :ensure_slug
|
||||||
after_save :invalidate_site_cache
|
|
||||||
before_save :apply_permissions
|
before_save :apply_permissions
|
||||||
after_create :create_category_definition
|
after_create :create_category_definition
|
||||||
after_create :publish_categories_list
|
after_create :publish_categories_list
|
||||||
after_destroy :invalidate_site_cache
|
|
||||||
after_destroy :publish_categories_list
|
after_destroy :publish_categories_list
|
||||||
|
|
||||||
has_one :category_search_data
|
has_one :category_search_data
|
||||||
@ -221,12 +219,6 @@ SQL
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Categories are cached in the site json, so the caches need to be
|
|
||||||
# invalidated whenever the category changes.
|
|
||||||
def invalidate_site_cache
|
|
||||||
Site.invalidate_cache
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish_categories_list
|
def publish_categories_list
|
||||||
MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json})
|
MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json})
|
||||||
end
|
end
|
||||||
|
@ -54,12 +54,7 @@ class Site
|
|||||||
Archetype.list.reject { |t| t.id == Archetype.private_message }
|
Archetype.list.reject { |t| t.id == Archetype.private_message }
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_key
|
def self.json_for(guardian)
|
||||||
k = "site_json_cats_"
|
|
||||||
k << @guardian.secure_category_ids.join("_") if @guardian
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.cached_json(guardian)
|
|
||||||
|
|
||||||
if guardian.anonymous? && SiteSetting.login_required
|
if guardian.anonymous? && SiteSetting.login_required
|
||||||
return {
|
return {
|
||||||
@ -72,7 +67,4 @@ class Site
|
|||||||
MultiJson.dump(SiteSerializer.new(site, root: false))
|
MultiJson.dump(SiteSerializer.new(site, root: false))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.invalidate_cache
|
|
||||||
Discourse.cache.delete_by_family("site")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -145,25 +145,6 @@ describe Category do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'caching' do
|
|
||||||
it "invalidates the site cache on creation" do
|
|
||||||
Site.expects(:invalidate_cache).once
|
|
||||||
Fabricate(:category)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "invalidates the site cache on update" do
|
|
||||||
cat = Fabricate(:category)
|
|
||||||
Site.expects(:invalidate_cache).once
|
|
||||||
cat.update_attributes(name: 'new name')
|
|
||||||
end
|
|
||||||
|
|
||||||
it "invalidates the site cache on destroy" do
|
|
||||||
cat = Fabricate(:category)
|
|
||||||
Site.expects(:invalidate_cache).once
|
|
||||||
cat.destroy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'non-english characters' do
|
describe 'non-english characters' do
|
||||||
let(:category) { Fabricate(:category, name: "電車男") }
|
let(:category) { Fabricate(:category, name: "電車男") }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user