Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
658 stars 90 forks source link

Callback of a direct update forces direct on operations within callback #243

Closed evolross closed 5 years ago

evolross commented 6 years ago

Version: matb33:collection-hooks@0.9.0-rc.4

Just reporting for the heck of it - I know this really isn't supported anymore, but it works for the most part. If I get time I may try to work on this.

In server code I have:

someCollection.direct.update({...}, function(error) {
   if(!error) {
      anotherCollection.update({...});
   }
});

The update to anotherCollection gets the direct bypasser forced onto it.

zimme commented 6 years ago

Haven't looked at the code for a while, but thinking that some fiber environment variable is being set and as the update on anotherCollection is run in the same fiber or a cloned fiber environment it also runs in direct mode.

But not sure

evolross commented 5 years ago

Just ran into this again... and figured something out as a work-around/solution (after a lot of shots in the dark). If you throw in a CollectionHooks.directEnv = new Meteor.EnvironmentVariable(false) like so:

someCollection.direct.update({...}, function(error) {
   if(!error) {
      CollectionHooks.directEnv = new Meteor.EnvironmentVariable(false);
      anotherCollection.update({...});
   }
});

It disregards the direct on the second update. Thanks for the advice. It was indeed a fiber environment variable.