Skip to content
Permalink
Browse files

.find() and update onAction only fetch _id field

_dontPublish get deleted before applying it
  • Loading branch information
arunoda committed May 15, 2013
1 parent 4866392 commit 64bde6c8fa016b64ba2f95285a301d2a9da36671
Showing with 14 additions and 12 deletions.
  1. +13 −11 lib/cluster.js
  2. +1 −1 smart.json
@@ -7,7 +7,6 @@ function Cluster() {
var collections = {};

this.sync = function() {

_.each(arguments, function(collection) {
collections[collection._name] = collection;
watchCollection(collection);
@@ -45,20 +44,24 @@ function Cluster() {
methods.forEach(function(method) {
var original = collection._collection[method];
collection._collection[method] = function() {
//find a better way to do this rather than ._dontPublish
//delete is expensive
var dontPublish = arguments[0]._dontPublish;
delete arguments[0]._dontPublish;
original.apply(collection, arguments);
publishAction(collection._name, method, arguments);

if(!dontPublish) {
publishAction(collection._name, method, arguments);
}
};
});
}

function publishAction(collectionName, method, arguments) {

if(!(arguments[0]._dontPublish)) {
if(method == 'insert') {
arguments = [{_id: arguments[0]._id}];
}
onAction(collectionName, method, arguments);
function publishAction(collectionName, method, arguments) {
if(method == 'insert') {
arguments = [{_id: arguments[0]._id}];
}
onAction(collectionName, method, arguments);
}

function onAction(collectionName, method, args) {
@@ -71,7 +74,6 @@ function Cluster() {
}

function onMessage(collectionName, method, args) {

var collection = collections[collectionName];
var Fiber = Npm.require('fibers');

@@ -83,7 +85,7 @@ function Cluster() {
} else if (method == 'update') {
//get this from somewhere else
Fiber(function() {
var docs = collection.find(args[0]);
var docs = collection.find(args[0], {fields: {_id: 1}});
docs.forEach(function(doc) {
var query = {_id: doc._id, _dontPublish: true};
collection.update(query, {$set: {}});
@@ -3,6 +3,6 @@
"description": "Smarter way to run cluster of meteor nodes",
"homepage": "https://github.com/arunoda/meteor-cluster",
"author": "Arunoda Susiripala <arunoda.susiripala@gmail.com>",
"version": "0.1.3",
"version": "0.1.4",
"git": "https://github.com/arunoda/meteor-cluster.git"
}

0 comments on commit 64bde6c

Please sign in to comment.
You can’t perform that action at this time.