javascript - 强制 Meteor 更新远程更改?

标签 javascript mongodb meteor

我有一个 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算法,该算法是

  1. 昂贵(CPU 和内存)
  2. 每 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/

相关文章:

javascript - 如何创建多选以显示 Django 中每个选定内容的详细信息?

node.js - Mongoose 和 promise : how to get an array of query results?

php - mongodb 中的 mysql hour() 方法?

javascript - 从 Meteor 中的父访问子模板助手/变量

javascript - Meteor.Methods 在一个函数中,可能的架构解决方案

javascript - 在 webGL 中渲染圆环时出现问题

javascript 模块模式适用于 jsbin,但不适用于我的服务器/浏览器

mongodb - 在双重嵌套数组中查找

javascript - 使用导入,服务器如何与客户端通信?

javascript - 使用 PHP 和 Javascript 的正确登录屏幕