FIX: Clear `Site#categories` cache when git sha changes.

Category custom fields are cached so we need to break the cache when a
new plugin is added/removed.
This commit is contained in:
Alan Guo Xiang Tan 2021-07-22 15:18:18 +08:00
parent 0ce9fd12d0
commit ffb3e7b356
1 changed files with 5 additions and 3 deletions

View File

@ -35,10 +35,12 @@ class Site
UserField.order(:position).all
end
CATEGORIES_CACHE_KEY = "site_categories"
def self.categories_cache_key
"site_categories_#{Discourse.git_version}"
end
def self.clear_cache
Discourse.cache.delete(CATEGORIES_CACHE_KEY)
Discourse.cache.delete(categories_cache_key)
end
def self.all_categories_cache
@ -47,7 +49,7 @@ class Site
#
# Do note that any new association added to the eager loading needs a
# corresponding ActiveRecord callback to clear the categories cache.
Discourse.cache.fetch(CATEGORIES_CACHE_KEY, expires_in: 30.minutes) do
Discourse.cache.fetch(categories_cache_key, expires_in: 30.minutes) do
categories = Category
.includes(:uploaded_logo, :uploaded_background, :tags, :tag_groups, :required_tag_group)
.joins('LEFT JOIN topics t on t.id = categories.topic_id')