You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stale data is received if doing a findOne after an update #13
If quickly doing a findOne(field) after an update() then stale data is received. Contrived example:
constname=Meteor.user('profile').profile.name;console.log('before',name);// -> "bob"Meteor.users.update(Meteor.userId(),{$set: {"profile.name": name+name.length}});console.log('after ',Meteor.user('profile').profile.name);// -> "bob" - should be "bob3"
This is a contrived example for demonstration purposes, but I have hit this bug in real production code.
My work-around involves a bit of a hack of Meteor.EnvironmentVariable to set an environment variable within the Fiber whenever the Meteor.users collection is updated:
const_origUpdate=Meteor.users.update;constupdated=newMeteor.EnvironmentVariable();varFiber=Npm.require('fibers');// https://github.com/meteor/meteor/blob/096641b084b70f4ab52f3ef4468728d164ec66d1/packages/meteor/dynamics_nodejs.js#L47Meteor.EnvironmentVariable.prototype.set=function(value){Meteor._nodeCodeMustBeInFiber();if(!Fiber.current._meteor_dynamics)Fiber.current._meteor_dynamics=[];varcurrentValues=Fiber.current._meteor_dynamics;currentValues[this.slot]=value;}// Set an environment variable whenever the Meteor.users collection is updatedMeteor.users.update=function(...args){updated.set(true);return_origUpdate.apply(this,args);}Meteor.user=function(input){// don't hit the cache if the Meteor.users collection has been updated in this Fiberif(typeofinput==="undefined"||updated.get()){return_original();}
...
changed the title [-]Stale data is received if doing a findOne after an upate[/-][+]Stale data is received if doing a findOne after an upsate[/+]on Feb 7, 2020
changed the title [-]Stale data is received if doing a findOne after an upsate[/-][+]Stale data is received if doing a findOne after an update[/+]on Feb 7, 2020
Activity
wildhart commentedon Dec 23, 2019
FYI, I've written a meteor package wildhart:env-var-set which adds the
EnviromentVariable.set()method so feel free to re-use that if you want.I've used it within wildhart:mergebox-cache which is my own fork of
userCachewhich works with all collections, not justMeteor.users.[-]Stale data is received if doing a findOne after an upate[/-][+]Stale data is received if doing a findOne after an upsate[/+][-]Stale data is received if doing a findOne after an upsate[/-][+]Stale data is received if doing a findOne after an update[/+]