Fix bulletin feed cache bug when destroy bulletin.
This commit is contained in:
parent
fa6044d451
commit
18f31caa2d
|
@ -3,15 +3,20 @@ module BulletinModel
|
|||
require 'active_support/concern'
|
||||
extend ActiveSupport::Concern
|
||||
included do
|
||||
after_save :do_before_save
|
||||
before_destroy :do_before_save
|
||||
after_save :cache_tag_ids, :do_before_save
|
||||
after_destroy :do_before_save
|
||||
before_destroy :cache_tag_ids
|
||||
end
|
||||
def cache_tag_ids
|
||||
@tag_ids = self.tag_ids
|
||||
@org_tag_ids = self.org_tag_ids
|
||||
end
|
||||
def do_before_save
|
||||
if self.class == SubPart
|
||||
AnnsCache.where(parent_id: self.id).delete
|
||||
elsif self.class == Bulletin || (self.class == Page && self.module == "announcement")
|
||||
if self.class == Bulletin
|
||||
tmp_tag_ids = (Array(self.tag_ids) + Array(self.org_tag_ids)).uniq
|
||||
tmp_tag_ids = (Array(@tag_ids) + Array(@org_tag_ids)).uniq
|
||||
tmp_cat_ids = (Array(self.category_id) + Array(self.org_category_id)).uniq
|
||||
Thread.new do
|
||||
BulletinFeedCache.where(:uid.in => BulletinFeed.any_of([{:tag_ids.in => tmp_tag_ids.collect{|v| v.to_s}},{:category_ids.in => tmp_cat_ids.collect{|v| v.to_s}}]).pluck(:uid)).each do |cache|
|
||||
|
|
Loading…
Reference in New Issue