add index for feed

This commit is contained in:
邱博亞 2021-11-09 19:41:52 +08:00
parent 815ee7628c
commit 12a52c2b8c
3 changed files with 15 additions and 2 deletions

View File

@ -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}

View File

@ -0,0 +1,7 @@
class SiteFeedAnncCache
include Mongoid::Document
field :data
field :subpart_id
field :invalid_time
end

View File

@ -34,6 +34,7 @@ module Feeds
tmp.destroy
end
end
SiteFeedAnnc.create_indexes
end
rescue => e
puts ['feed_engine',e]