我有一个通过外部API修改的流星应用程序。 API修改Meteor应用程序读取的mongodb。我遇到的问题是,API正在对数据库进行的更改没有像我希望它们在我的meteor应用程序上那样快速地呈现。如果我每10秒向我的API发布一次新数据,我的meteor app似乎每30秒更新一次。如何提高流星更新/收听更改的速度?下面是我写的一些代码示例。
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
});
});
}
答案 0 :(得分:1)
您是否已将OpLog URL提供给您的流星后端?
如果没有,那么meteor正在使用poll-and-diff
算法
通过使用MongoDB OpLog,它将立即运行。
这对OpLog& amp;流星
https://meteorhacks.com/mongodb-oplog-and-meteor