fix error for multiple locale on

This commit is contained in:
chiu 2020-03-05 18:36:28 +08:00
parent e2f03069d0
commit 5314f282e1
2 changed files with 3 additions and 4 deletions

View File

@ -113,7 +113,7 @@ class AnnouncementsController < ApplicationController
tags = OrbitHelper.widget_tags || [] tags = OrbitHelper.widget_tags || []
cats = OrbitHelper.widget_categories || [] cats = OrbitHelper.widget_categories || []
subpart = OrbitHelper.get_current_widget subpart = OrbitHelper.get_current_widget
anns_cache = AnnsCache.where(parent_id: subpart.id) anns_cache = AnnsCache.where(parent_id: subpart.id,locale: I18n.locale.to_s)
widget_data_count = OrbitHelper.widget_data_count widget_data_count = OrbitHelper.widget_data_count
if !(defined? SiteFeed).nil? || anns_cache.count != 1 || is_random if !(defined? SiteFeed).nil? || anns_cache.count != 1 || is_random
page = Page.where(:module => "announcement").first rescue nil page = Page.where(:module => "announcement").first rescue nil
@ -128,7 +128,7 @@ class AnnouncementsController < ApplicationController
if anns_cache.count > 1 if anns_cache.count > 1
anns_cache.destroy anns_cache.destroy
end end
AnnsCache.create(parent_id: subpart.id,filter_result: sorted_anns.map{|v| v.id}) AnnsCache.create(parent_id: subpart.id,locale: I18n.locale.to_s,filter_result: sorted_anns.map{|v| v.id})
else else
sorted_anns = sorted_anns.sample(widget_data_count) sorted_anns = sorted_anns.sample(widget_data_count)
end end

View File

@ -2,6 +2,5 @@ class AnnsCache
include Mongoid::Document include Mongoid::Document
field :parent_id field :parent_id
field :filter_result,type: Array,default: [] field :filter_result,type: Array,default: []
field :tag_ids,type: Array,default: [] field :locale,type: String,default: 'zh_tw'
field :cat_ids,type: Array,default: []
end end