mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-03 09:25:18 -04:00
FIX: topic id cache should be a multi process cache
This commit is contained in:
parent
ab68e0c9db
commit
83f80341b3
1 changed files with 9 additions and 7 deletions
|
@ -61,8 +61,8 @@ class Category < ActiveRecord::Base
|
||||||
has_many :category_tag_groups, dependent: :destroy
|
has_many :category_tag_groups, dependent: :destroy
|
||||||
has_many :tag_groups, through: :category_tag_groups
|
has_many :tag_groups, through: :category_tag_groups
|
||||||
|
|
||||||
after_save :clear_topic_ids_cache
|
after_save :reset_topic_ids_cache
|
||||||
after_destroy :clear_topic_ids_cache
|
after_destroy :reset_topic_ids_cache
|
||||||
|
|
||||||
scope :latest, -> { order('topic_count DESC') }
|
scope :latest, -> { order('topic_count DESC') }
|
||||||
|
|
||||||
|
@ -86,16 +86,18 @@ class Category < ActiveRecord::Base
|
||||||
# we may consider wrapping this in another spot
|
# we may consider wrapping this in another spot
|
||||||
attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level, :has_children
|
attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level, :has_children
|
||||||
|
|
||||||
|
@topic_id_cache = DistributedCache.new('category_topic_ids')
|
||||||
|
|
||||||
def self.topic_ids
|
def self.topic_ids
|
||||||
@topic_ids ||= Set.new(Category.pluck(:topic_id).compact)
|
@topic_id_cache['ids'] || reset_topic_ids_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.clear_topic_ids_cache
|
def self.reset_topic_ids_cache
|
||||||
@topic_ids = nil
|
@topic_id_cache['ids'] = Set.new(Category.pluck(:topic_id).compact)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_topic_ids_cache
|
def reset_topic_ids_cache
|
||||||
Category.clear_topic_ids_cache
|
Category.reset_topic_ids_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.last_updated_at
|
def self.last_updated_at
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue