Skip to content

A platform for community discussion. Free, open, simple.

DEV: Make category subcategory_ids cache work like other caches (#20815)

Daniel Waterworth3e80ab314382
diff --git a/app/models/category.rb b/app/models/category.rb
index a78b91cd4e6..9c49f86f2ac 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -218,7 +218,7 @@ class Category < ActiveRecord::Base
@@subcategory_ids = DistributedCache.new("subcategory_ids")
def self.subcategory_ids(category_id)
- @@subcategory_ids[category_id] ||= begin
+ @@subcategory_ids.defer_get_set(category_id.to_s) do
sql = <<~SQL
WITH RECURSIVE subcategories AS (
SELECT :category_id id, 1 depth