1
我有一個流星應用程序正在通過外部API進行修改。 API修改Meteor應用程序讀取的mongodb。我遇到的問題是,API對數據庫所做的更改沒有像我希望它們在我的流星應用程序中那樣快速地呈現。如果我每10秒向我的API發佈新數據,我的流星應用程序似乎只會每30秒更新一次。我怎樣才能提高流星更新/監聽變化的速度?下面是我寫的一些代碼的示例。Force 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
});
});
}
多久更新需要傳播到你的客戶是有益的直接從mongo控制檯進行更改?這可以幫助縮小問題的範圍。你在做什麼應該幾乎是瞬間的。 –
當我直接從控制檯進行更改時,大約需要5-10秒才能在客戶端進行傳播。這不是本地控制檯。 – traviswingo
兩種行爲都不正常。下面有@webdeb有一個有趣的線索。 –