强制流星更新远程更改?

时间:2015-11-08 21:41:54

标签: javascript mongodb meteor

我有一个通过外部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
    });
  });
}

1 个答案:

答案 0 :(得分:1)

您是否已将OpLog URL提供给您的流星后端?
如果没有,那么meteor正在使用poll-and-diff算法

  1. 昂贵(cpu& memory)
  2. 每10秒运行一次(因为1。)
  3. 通过使用MongoDB OpLog,它将立即运行。

    这对OpLog& amp;流星
    https://meteorhacks.com/mongodb-oplog-and-meteor

    流星0.7博客帖子,第一次推出oplog时 http://info.meteor.com/blog/meteor-070-scalable-database-queries-using-mongodb-oplog-instead-of-poll-and-diff