Fix limit error.
This commit is contained in:
parent
c5a96e8917
commit
e3ab735f43
|
@ -159,38 +159,42 @@ class SiteFeedAnnc
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_feed_cache(channel_key,merge_with_category=nil,site_source=nil,locale=I18n.locale.to_s,is_widget=false,max_len=nil)
|
def self.get_feed_cache(channel_key,merge_with_category=nil,site_source=nil,locale=I18n.locale.to_s,is_widget=false,max_len=nil)
|
||||||
match_cond = {"channel_key"=>channel_key}
|
max_len = ((max_len.to_i < 0 rescue true) ? 0 : max_len.to_i)
|
||||||
if !merge_with_category.blank? && merge_with_category.exclude?('all')
|
if max_len > 0
|
||||||
match_cond["merge_with_category"] = {"$in"=>merge_with_category}
|
match_cond = {"channel_key"=>channel_key}
|
||||||
end
|
if !merge_with_category.blank? && merge_with_category.exclude?('all')
|
||||||
if site_source
|
match_cond["merge_with_category"] = {"$in"=>merge_with_category}
|
||||||
match_cond["channel_title.#{locale}"] = site_source
|
|
||||||
end
|
|
||||||
pipeline = [
|
|
||||||
{"$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"=>""}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
max_len = 0 if (max_len.to_i < 0 rescue true)
|
|
||||||
if max_len
|
|
||||||
pipeline << {"$limit"=> max_len}
|
|
||||||
end
|
|
||||||
self.collection.aggregate(pipeline).collect do |data|
|
|
||||||
tmp = data['data']
|
|
||||||
if tmp["link_to_show"].nil?
|
|
||||||
if !is_widget
|
|
||||||
tmp["link_to_show"] = OrbitHelper.url_to_show(tmp["params"]) rescue ''
|
|
||||||
else
|
|
||||||
tmp["link_to_show"] = OrbitHelper.widget_item_url(tmp["params"]) rescue ''
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
tmp
|
if site_source
|
||||||
|
match_cond["channel_title.#{locale}"] = site_source
|
||||||
|
end
|
||||||
|
pipeline = [
|
||||||
|
{"$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"=>""}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
if max_len
|
||||||
|
pipeline << {"$limit"=> max_len}
|
||||||
|
end
|
||||||
|
self.collection.aggregate(pipeline).collect do |data|
|
||||||
|
tmp = data['data']
|
||||||
|
if tmp["link_to_show"].nil?
|
||||||
|
if !is_widget
|
||||||
|
tmp["link_to_show"] = OrbitHelper.url_to_show(tmp["params"]) rescue ''
|
||||||
|
else
|
||||||
|
tmp["link_to_show"] = OrbitHelper.widget_item_url(tmp["params"]) rescue ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tmp
|
||||||
|
end
|
||||||
|
else
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue