mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05: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:
parent
7f2512b707
commit
3151f59bc9
4 changed files with 2 additions and 37 deletions
|
@ -215,7 +215,7 @@ class ApplicationController < ActionController::Base
|
|||
private
|
||||
|
||||
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("customHTML", custom_html_json)
|
||||
end
|
||||
|
|
|
@ -28,11 +28,9 @@ class Category < ActiveRecord::Base
|
|||
validate :parent_category_validator
|
||||
|
||||
before_validation :ensure_slug
|
||||
after_save :invalidate_site_cache
|
||||
before_save :apply_permissions
|
||||
after_create :create_category_definition
|
||||
after_create :publish_categories_list
|
||||
after_destroy :invalidate_site_cache
|
||||
after_destroy :publish_categories_list
|
||||
|
||||
has_one :category_search_data
|
||||
|
@ -221,12 +219,6 @@ SQL
|
|||
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
|
||||
MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json})
|
||||
end
|
||||
|
|
|
@ -54,12 +54,7 @@ class Site
|
|||
Archetype.list.reject { |t| t.id == Archetype.private_message }
|
||||
end
|
||||
|
||||
def cache_key
|
||||
k = "site_json_cats_"
|
||||
k << @guardian.secure_category_ids.join("_") if @guardian
|
||||
end
|
||||
|
||||
def self.cached_json(guardian)
|
||||
def self.json_for(guardian)
|
||||
|
||||
if guardian.anonymous? && SiteSetting.login_required
|
||||
return {
|
||||
|
@ -72,7 +67,4 @@ class Site
|
|||
MultiJson.dump(SiteSerializer.new(site, root: false))
|
||||
end
|
||||
|
||||
def self.invalidate_cache
|
||||
Discourse.cache.delete_by_family("site")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -145,25 +145,6 @@ describe Category do
|
|||
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
|
||||
let(:category) { Fabricate(:category, name: "電車男") }
|
||||
|
||||
|
|
Loading…
Reference in a new issue