From 12a52c2b8c968a69b3b1446e12b0a86ad5783cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Tue, 9 Nov 2021 19:41:52 +0800 Subject: [PATCH] add index for feed --- app/models/site_feed_annc.rb | 9 +++++++-- app/models/site_feed_annc_cache.rb | 7 +++++++ lib/feeds/engine.rb | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/models/site_feed_annc_cache.rb diff --git a/app/models/site_feed_annc.rb b/app/models/site_feed_annc.rb index 97ae61a..cd781b7 100644 --- a/app/models/site_feed_annc.rb +++ b/app/models/site_feed_annc.rb @@ -12,6 +12,11 @@ class SiteFeedAnnc field :merge_with_category field :remote_site_url field :channel_title + I18n.available_locales.each do |locale| + index({ "all_contents_for_feed.#{locale}.is_hidden"=> -1, + "all_contents_for_feed.#{locale}.is_top"=> -1, + "all_contents_for_feed.#{locale}.postdate"=> -1}, { unique: false, background: true }) + end def get_annc(annc_uid) Array(self[:all_contents_for_feed]).select{|v| v['id']==annc_uid}[0] rescue {} end @@ -164,12 +169,12 @@ class SiteFeedAnnc {"$match"=>match_cond}, {"$project"=>{"data"=>"$all_contents_for_feed.#{locale}"}}, {"$unwind"=>"$data"}, + {"$sort"=>{"data.is_hidden"=>-1,"data.is_top"=>-1,"data.postdate"=>-1}}, {"$match"=>{"data.is_hidden"=>{"$ne"=>true}, "data.postdate"=>{"$lte"=>Time.now}, "data.title" => {"$gt"=>""} } - }, - {"$sort"=>{"data.is_top"=>-1,"data.postdate"=>-1}} + } ] if max_len pipeline << {"$limit"=> max_len} diff --git a/app/models/site_feed_annc_cache.rb b/app/models/site_feed_annc_cache.rb new file mode 100644 index 0000000..30e4a2c --- /dev/null +++ b/app/models/site_feed_annc_cache.rb @@ -0,0 +1,7 @@ +class SiteFeedAnncCache + include Mongoid::Document + field :data + field :subpart_id + field :invalid_time + +end \ No newline at end of file diff --git a/lib/feeds/engine.rb b/lib/feeds/engine.rb index 8a811e4..dce33df 100644 --- a/lib/feeds/engine.rb +++ b/lib/feeds/engine.rb @@ -34,6 +34,7 @@ module Feeds tmp.destroy end end + SiteFeedAnnc.create_indexes end rescue => e puts ['feed_engine',e]