diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 72d98a8..44e8e0c 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -10,14 +10,28 @@ class Bulletin include Slug require 'bulletin_model/cache' include BulletinModel::Cache - attr_accessor :org_tag_ids + attr_accessor :org_tag_ids,:org_category_id def tags=(ids) self.org_tag_ids = self.tag_ids super(ids) end + def category=(cat) + self.org_category_id = self.category_id + super(cat) + end + def tag_ids=(ids) + self.org_tag_ids = self.tag_ids + super(ids) + end + def category_id=(cat_id) + self.org_category_id = self.category_id + super(cat_id) + end def []=(index,value) - if index.to_s=='tags' + if index.to_s=='tags' || index.to_s=='tag_ids' self.org_tag_ids = self.tag_ids + elsif index.to_s=='category' || index.to_s=='category_id' + self.org_category_id = self.category_id end super(index,value) end diff --git a/lib/bulletin_model/cache.rb b/lib/bulletin_model/cache.rb index 6317e96..4c49880 100644 --- a/lib/bulletin_model/cache.rb +++ b/lib/bulletin_model/cache.rb @@ -12,8 +12,9 @@ module BulletinModel 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_cat_ids = (Array(self.category_id) + Array(self.org_category_id)).uniq Thread.new do - BulletinFeedCache.where(:uid.in => BulletinFeed.where(:tag_ids.in => tmp_tag_ids.collect{|v| v.to_s}).pluck(:uid)).each do |cache| + 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| cache.regenerate end end