mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:57:36 +08:00
FIX: topic id cache should be a multi process cache
This commit is contained in:
parent
ab68e0c9db
commit
83f80341b3
|
@ -61,8 +61,8 @@ class Category < ActiveRecord::Base
|
|||
has_many :category_tag_groups, dependent: :destroy
|
||||
has_many :tag_groups, through: :category_tag_groups
|
||||
|
||||
after_save :clear_topic_ids_cache
|
||||
after_destroy :clear_topic_ids_cache
|
||||
after_save :reset_topic_ids_cache
|
||||
after_destroy :reset_topic_ids_cache
|
||||
|
||||
scope :latest, -> { order('topic_count DESC') }
|
||||
|
||||
|
@ -86,16 +86,18 @@ class Category < ActiveRecord::Base
|
|||
# we may consider wrapping this in another spot
|
||||
attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level, :has_children
|
||||
|
||||
@topic_id_cache = DistributedCache.new('category_topic_ids')
|
||||
|
||||
def self.topic_ids
|
||||
@topic_ids ||= Set.new(Category.pluck(:topic_id).compact)
|
||||
@topic_id_cache['ids'] || reset_topic_ids_cache
|
||||
end
|
||||
|
||||
def self.clear_topic_ids_cache
|
||||
@topic_ids = nil
|
||||
def self.reset_topic_ids_cache
|
||||
@topic_id_cache['ids'] = Set.new(Category.pluck(:topic_id).compact)
|
||||
end
|
||||
|
||||
def clear_topic_ids_cache
|
||||
Category.clear_topic_ids_cache
|
||||
def reset_topic_ids_cache
|
||||
Category.reset_topic_ids_cache
|
||||
end
|
||||
|
||||
def self.last_updated_at
|
||||
|
|
Loading…
Reference in New Issue
Block a user