Meteor JS:服务器端observeChanges性能问题

时间:2014-08-04 11:12:05

标签: performance meteor aggregation

我正在实施服务器端反应式聚合,并且使用observeChanges方法遇到了一些性能问题。

Meteor.publish("ReactiveGroup", function (collectionName, filter, groupRules, options) {
    var self = this;
    var aggregate = function() {     
        var agregationPipe = _.clone(groupRules);
        agregationPipe.unshift({
            $match: filter
        });
        return collection.aggregate(agregationPipe);
    };

    var handle = collection.find(filter).observeChanges({
        _suppress_initial: true,
        changed: function(id, doc) {
            self.changed('ReactiveGroup', 0, aggregate());
        },
        removed: function (id, doc) {
            self.changed('ReactiveGroup', 0, aggregate());
        }
    });

    self.added('ReactiveGroup', 0, aggregate());
    self.ready();
});

在上面的代码中,大气扩展mongodb-server-aggregation被使用

过滤的集合返回大约200k的记录,并且聚合本身工作速度非常快 - 大约1秒,但observeChanges执行大约需要20秒,因为无论是否存在添加的回调,它都会触发所有添加的事件。

如果有任何方法可以在observeChanges方法中禁用添加的事件?

0 个答案:

没有答案
相关问题