FIX: topic id cache should be a multi process cache

This commit is contained in:
Sam 2016-07-28 10:20:14 +10:00
parent ab68e0c9db
commit 83f80341b3
1 changed files with 9 additions and 7 deletions

View File

@ -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