处理一个项目,解析来自各个站点的新闻门户新闻,Stack NodeJs + Express + MongoDb + ReactJS。
我认为我在查询主页数据库时遇到问题,要求获取超过7个获取新闻源的请求,4个不同类别的5个最新新闻,热门视频和新闻浏览等。< / p>
我认为第一个版本是愚蠢的
news.find({}, {....}).toArray(function(err, data) {
var NewsArray = data;
politics.find({}, {....}).toArray(function(err, data) {
var politicsArray = data;
.... / There is still a lot of requests , and in the end render with all the variables .
}
});
第二种选择甚至不知道也无法纠正。
var _timer = 0,
newsArray,
politicsArray;
news.find({}, {....}).toArray(function(err, data) {
newsArray = data;
_timer++;
})
politics.find({}, {....}).toArray(function(err, data) {
politicsArray = data;
_timer++;
})
Another 6 queries ....
renderToPage();
function renderToPage(){
if(_timer != 8(in example)){
setTimeout(render, 100)
} else {
res.render(".....", {})
}
}
请帮助精美表格请求它很好并且不发送服务器,然后两个查询选择一个类别和其他50个有限制的新闻项目。已经DomContentLoaded 2,3秒