From 9f7dfafe959169bcf6223eca9d984ab40928d0ff Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 6 May 2020 18:23:04 +0800 Subject: [PATCH] cache the whole bulletin content --- app/controllers/announcements_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 9df117a..f71e946 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -129,14 +129,12 @@ class AnnouncementsController < ApplicationController if anns_cache.count > 1 anns_cache.destroy end - AnnsCache.create(parent_id: subpart.id.to_s,locale: I18n.locale.to_s,filter_result: sorted_anns.pluck(:id)) + AnnsCache.create(parent_id: subpart.id.to_s,locale: I18n.locale.to_s,filter_result: sorted_anns.to_a.to_yaml) else sorted_anns = sorted_anns.sample(widget_data_count) end else - sorted_ann_ids = anns_cache.first.filter_result - sorted_anns = Bulletin.find(sorted_ann_ids) - sorted_anns = sorted_ann_ids.map{|v1| sorted_anns.find{|v2| v2.id==v1}} + sorted_anns = YAML.load(anns_cache.first.filter_result) end if (defined? SiteFeed).nil? || is_random anns = sorted_anns.map{|v| data_to_human_type(v)}