traviswingo
traviswingo

Reputation: 315

Force Meteor to Update on Remote Changes?

I have a meteor app that's being modified via an external API. The API modifies the mongodb that the Meteor app reads from. The problem I'm running into is that the changes the API are making to the database are not being rendered as quickly as I'd like them to be on my meteor app. If I post new data to my API every 10 seconds, my meteor app seems to only be updating every 30 seconds. How can I increase the rate at which meteor updates/listens to changes? Below is a sample of some code I wrote.

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
    });
  });
}

Upvotes: 1

Views: 358

Answers (1)

webdeb
webdeb

Reputation: 13211

Have you provided the OpLog URL to your meteor backend?
If not, then meteor is using the poll-and-diff algorithm which is

  1. expensive (cpu & memory)
  2. runs only every 10 seconds (because of 1.)

By using MongoDB OpLog it will run immediately.

This should be useful regarding OpLog & Meteor
https://meteorhacks.com/mongodb-oplog-and-meteor

Meteor 0.7 blog post, when the introduced oplog for the first time
http://info.meteor.com/blog/meteor-070-scalable-database-queries-using-mongodb-oplog-instead-of-poll-and-diff

Upvotes: 1

Related Questions