From 3151f59bc984f46411daed933c5a275b919a3412 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 24 Feb 2014 14:24:18 -0500 Subject: [PATCH] REFACTOR: We don't cache the json for the Site model anymore, so let's rename and remove the methods leftover from that. --- app/controllers/application_controller.rb | 2 +- app/models/category.rb | 8 -------- app/models/site.rb | 10 +--------- spec/models/category_spec.rb | 19 ------------------- 4 files changed, 2 insertions(+), 37 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 494df9ba3..5fc1f2ead 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/models/category.rb b/app/models/category.rb index ffc79b85a..4449c8da5 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -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 diff --git a/app/models/site.rb b/app/models/site.rb index fe2c4c8a3..55abb9714 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -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 diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index e361455a3..98f2dcf4f 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -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: "電車男") }