fix error

This commit is contained in:
邱博亞 2021-11-18 15:07:34 +08:00
parent 3381ce7190
commit 5e7df7753a
3 changed files with 13 additions and 6 deletions

View File

@ -85,7 +85,8 @@ class Bulletin
before_destroy :destroy_email before_destroy :destroy_email
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)} scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
scope :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil,:deadline.gte=>Time.now},{:postdate=>nil,:deadline=>nil}).order(is_top: :desc,postdate: :desc,id: :desc)} scope :can_display_and_sorted, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true).valid_time_range}
scope :valid_time_range, ->{any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil,:deadline.gte=>Time.now},{:postdate=>nil,:deadline=>nil}).order(is_top: :desc,postdate: :desc,id: :desc)}
scope :is_approved, ->{where(:approved => true)} scope :is_approved, ->{where(:approved => true)}
scope :is_approved_and_show, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true)} scope :is_approved_and_show, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true)}
scope :filter_cats_and_tags, ->(cats,tags) {filter_by_widget_categories(cats,false).filter_by_tags(tags)} scope :filter_cats_and_tags, ->(cats,tags) {filter_by_widget_categories(cats,false).filter_by_tags(tags)}
@ -93,7 +94,7 @@ class Bulletin
before_save :check_limit before_save :check_limit
index({postdate: 1}, { unique: false, background: true }) index({postdate: 1}, { unique: false, background: true })
index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true }) index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true })
index({is_hidden: 1,is_preview: 1, is_top: -1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true }) index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
def get_org_model def get_org_model
if self.is_preview if self.is_preview
org_model = nil org_model = nil

View File

@ -59,7 +59,8 @@ class BulletinFeed
tags = bf.tag_ids tags = bf.tag_ids
categories = bf.category_ids categories = bf.category_ids
if !(categories.empty? && tags.empty?) if !(categories.empty? && tags.empty?)
anns_before_filter = Bulletin.any_of(I18n.available_locales.map{|v| {"title.#{v}"=>{"$nin"=>["", nil]}}}).is_approved_and_show anns_before_filter = Bulletin.is_approved_and_show
can_display_and_sorted_flag = false
if !dt.nil? if !dt.nil?
dt = DateTime.parse(dt) dt = DateTime.parse(dt)
dtt = dt + 1.day dtt = dt + 1.day
@ -72,15 +73,20 @@ class BulletinFeed
startdt = DateTime.parse(startdt) startdt = DateTime.parse(startdt)
enddt = DateTime.parse(enddt) + 1.day enddt = DateTime.parse(enddt) + 1.day
anns_before_filter = anns_before_filter.where(:postdate.gt => startdt, :postdate.lt => enddt) anns_before_filter = anns_before_filter.where(:postdate.gt => startdt, :postdate.lt => enddt)
else
can_display_and_sorted_flag = true
end end
anns_before_filter = anns_before_filter.can_display_and_sorted
if !tags.empty? if !tags.empty?
anns_before_filter = anns_before_filter.filter_by_tags(tags) anns_before_filter = anns_before_filter.filter_by_tags(tags)
end end
if !categories.empty? if !categories.empty?
anns_before_filter = anns_before_filter.filter_by_categories(categories) anns_before_filter = anns_before_filter.filter_by_categories(categories)
end end
announcements = anns_before_filter.can_display_and_sorted anns_before_filter.selector = {"$and"=>[anns_before_filter.selector,{"$or"=>(I18n.available_locales.map{|v| {"title.#{v}"=>{"$nin"=>["", nil]}}})}]}
if can_display_and_sorted_flag
announcements = anns_before_filter.valid_time_range
end
else else
announcements = [] announcements = []
end end

View File

@ -23,7 +23,7 @@ class BulletinFeedCache
et = self.end et = self.end
dt = self.date dt = self.date
uid = self.uid uid = self.uid
BulletinFeed.where(uid: uid).first.generate_one_cache(startdt: st,enddt: et,dt: dt) rescue nil BulletinFeed.where(uid: uid).each{|v| v.generate_one_cache(startdt: st,enddt: et,dt: dt)} rescue nil
self.destroy self.destroy
end end
end end