我有一个 meteor 应用程序,正在通过外部 API 进行修改。该 API 修改 Meteor 应用程序读取的 mongodb。我遇到的问题是 API 对数据库所做的更改没有像我希望的那样快地呈现在我的 Meteor 应用程序上。如果我每 10 秒向 API 发布一次新数据,我的 Meteor 应用程序似乎每 30 秒更新一次。如何提高 meteor 更新/监听变化的速度?下面是我编写的一些代码示例。
UsageData = new Mongo.Collection('UsageData');
if (Meteor.isClient) {
// This code only runs on the client
angular.module('dashboard', ['angular-meteor']);
angular.module('dashboard').controller('DashboardCtrl', ['$scope', '$meteor',
function($scope, $meteor) {
$scope.$meteorSubscribe('usageData');
$scope.query = {};
$scope.data = $meteor.collection(function() {
return UsageData.find($scope.getReactively('query'), {
sort: {
createdAt: -1
},
limit: 1
});
});
}
]);
}
// This code only runs on the server
if (Meteor.isServer) {
Meteor.publish('usageData', function() {
return UsageData.find({}, {
sort: {
createdAt: -1
},
limit: 20
});
});
}
最佳答案
您是否向您的meteor后端提供了OpLog URL?
如果不是,那么meteor正在使用poll-and-diff
算法,该算法是
- 昂贵(CPU 和内存)
- 每 10 秒运行一次(因为 1。)
通过使用 MongoDB OpLog,它将立即运行。
这对于 OpLog 和 Meteor 应该很有用
https://meteorhacks.com/mongodb-oplog-and-meteor
Meteor 0.7博文,第一次引入oplog时
http://info.meteor.com/blog/meteor-070-scalable-database-queries-using-mongodb-oplog-instead-of-poll-and-diff
关于javascript - 强制 Meteor 更新远程更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33599348/