Files
curation-rails7/lib/curation/cache.rb
T
2025-05-07 22:25:46 +08:00

27 lines
763 B
Ruby

module Curation
module Cache
require 'active_support/concern'
extend ActiveSupport::Concern
included do
after_save :cache_tag_ids, :do_before_save
after_destroy :do_before_save
before_destroy :cache_tag_ids
end
def cache_tag_ids
if self.class == ::CurationPost
@tag_ids = self.tag_ids
@org_tag_ids = self.org_tag_ids
@category_id = self.category_id
@org_category_id = self.org_category_id
end
end
def do_before_save
if self.class == ::SubPart
::CurationCache.where(parent_id: /^#{self.id}/).delete
elsif self.class == ::CurationPost || (self.class == ::Page && self.module == "curation")
::CurationCache.all.delete
end
end
end
end