[英]Meteor js: The page taking too much time to query with mongodb if records are around 100000
我正在研究流星js,mongodb数据库中将有大量数据。 目前,数据库中大约有50000条消息。 我正在提供当前正在使用的代码。 由于某种原因,该应用程序花费太多时间来呈现或加载数据库中的数据。 还有一件事情,如果我正在做任何活动,例如,就像消息一样,应用程序再次从数据库中获取消息。
Template.messages.helper({
linkMessages() {
var ids = _.pluck(Meteor.user().subscription, '_id');
var messages = Messages.find({ $or: [{ feedId: { $exists: false }, link: { $exists: true } }, { feedId: { $in: ids }, link: { $exists: true } }] }, { sort: { timestamp: 1 }, limit: Session.get("linkMessageLimit") }).fetch();
return messages;
}
})
在oncreate方法中调用发布
Template.roomView.onCreated(function() {
const self = this;
Deps.autorun(function() {
Meteor.subscribe('messages', Session.get('currentRoom'), Session.get('textMessageLimit'), {
onReady() {
isReady.messages = true;
if (scroll.needScroll) {
scroll.needScroll = false;
if (scroll.previousMessage) {
Client.scrollToMessageText(scroll.previousMessage);
}
} else {
Meteor.setTimeout(function() {
Client.scrollChatToBottomMsg();
}, 1000)
}
}
});
});
});`
服务器上的发布功能:
Meteor.publish('messages', function(roomId, limit) {
check(roomId, String);
check(limit, Match.Integer);
let query = { $or: [{ link: {$exists: false} }, { feedId: { $exists: false } }] };
const thresholdMessage = Messages.findOne(query, { skip: limit, sort: { timestamp: 1 } });
if (thresholdMessage && thresholdMessage.timestamp) {
query.timestamp = { $gt: thresholdMessage.timestamp };
}
return Messages.find(query, { sort: { timestamp: -1 } });
});
允许mini-mongodb填充如此巨大的数据不是一个好习惯。 尽管Meteor JS也很擅长,但考虑网络流量,带宽等仍然需要花费一些时间。
无论是无限滚动还是简单分页,我都建议您使用分页。 我已经接受了它,它就像魅力一样工作, 这是答案和分页的整个代码 。
我的分页解决方案是特定于服务器的,因此性能良好。 集合发布仅限于订阅提供的limit
。
注意:对于带有搜索和分页功能的表格,还没有合适的完整解决方案,还有更多功能,这使得它可以根据我们的需要非常灵活。 我建议创建自己的。
更多见解:
https://www.quora.com/Does-Meteor-work-well-with-large-datasets
https://forums.meteor.com/t/very-big-data-collection-in-mongodb-how-to-fetch-in-meteor-js/6571/7
https://projectricochet.com/blog/top-10-meteor-performance-problems
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.