fix bug for anns cache

This commit is contained in:
BOYA,CHIU 2021-08-05 18:19:42 +08:00
parent 427222df41
commit 6ff4eecbc1
3 changed files with 20 additions and 11 deletions

View File

@ -59,6 +59,9 @@ class AnnouncementsController < ApplicationController
a a
end end
end end
if anns.count == 0 && params.any?{|k,v| v.class==Array ? v.any?{|v1| v1.to_s.match(/\*|\(|\)/)} : v.to_s.match(/\*|\(|\)/)}
return nil
end
#If no data , hide title&table #If no data , hide title&table
if sorted.count == 0 if sorted.count == 0
display = "hide" display = "hide"
@ -447,25 +450,29 @@ class AnnouncementsController < ApplicationController
anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s) anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
set_image_version_for_widget() set_image_version_for_widget()
devide_flag = (!(defined? SiteFeed).nil?) devide_flag = (!(defined? SiteFeed).nil?)
if anns_cache.count != 1 || is_random anns_cache.where(:invalid_date.lte => Time.now).destroy
if anns_cache.count > 1
anns_cache.skip(1).destroy
end
if anns_cache.count == 0 || is_random
Bulletin.remove_expired_status Bulletin.remove_expired_status
uid = OrbitHelper.params[:uid] rescue "" uid = OrbitHelper.params[:uid] rescue ""
sorted_anns = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil], :uid.ne => uid) anns_for_locale = Bulletin.where(:title.nin => ["",nil], :uid.ne => uid).is_approved.filter_cats_and_tags(cats,tags)
.can_display_and_sorted.is_approved sorted_anns = anns_for_locale.can_display_and_sorted
.filter_by_widget_categories(cats,false).filter_by_tags(tags)
if !is_random if !is_random
sorted_anns = sorted_anns.limit(widget_data_count) sorted_anns = sorted_anns.limit(widget_data_count)
if anns_cache.count > 1 first_deadline = sorted_anns.pluck(:deadline).compact.sort[0]
anns_cache.destroy first_postdate = anns_for_locale.open_in_future.limit(1).pluck(:postdate)[0]
end invalid_date = [first_postdate,first_deadline].compact.sort[0]
if devide_flag if devide_flag
now_anns = sorted_anns.to_a now_anns = sorted_anns.to_a
top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)} top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)} not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns}) AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns},invalid_date: invalid_date)
else else
anns = sorted_anns.map{|v| data_to_human_type(v,set_tags)} anns = sorted_anns.map{|v| data_to_human_type(v,set_tags)}
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns) AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns,invalid_date: invalid_date)
end end
else else
if devide_flag if devide_flag

View File

@ -3,4 +3,5 @@ class AnnsCache
field :parent_id field :parent_id
field :filter_result field :filter_result
field :locale,type: String,default: 'zh_tw' field :locale,type: String,default: 'zh_tw'
field :invalid_date, type: DateTime
end end

View File

@ -78,9 +78,10 @@ class Bulletin
before_destroy :destroy_email before_destroy :destroy_email
scope :can_display_and_sorted, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil}).order(is_top: :desc,postdate: :desc,id: :desc)} 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}).order(is_top: :desc,postdate: :desc,id: :desc)}
scope :is_approved, ->{where(:approved => true)} scope :is_approved, ->{where(:approved => true)}
scope :filter_cats_and_tags, ->(cats,tags) {filter_by_widget_categories(cats,false).filter_by_tags(tags)}
before_create :set_expire before_create :set_expire
before_save :check_limit before_save :check_limit
def to_calendar_param def to_calendar_param