-
Notifications
You must be signed in to change notification settings - Fork 367
Denormalize userId onto Todos collection #17
Comments
Check it out |
It seems like this would be super hard to implement correctly in general, since you need to parse the update modifier. Is there a way to do it somehow so that it doesn't involve writing a ton of code for all the different cases of |
Yeah, it's kind of the same problem as allow/deny. I'm not really sure what the best approach is. Would the following logic work?: const targetModifier = {};
const changingMods = _.each(modifier, (changes, mod) => {
if (_.has(changes, 'userId')) {
targetModifier[mod] = {userId: changes[userId]};
}
}); That would work for the An alternative would be to look at the source document after the update. I think the trick there is to detect if the field changes without doing unnecessary lookups. |
Would it maybe be OK to do one more lookup for each insert that does denormalization? |
If that's possible? This is on an update to the source collection -- I don't think we want to do an unnecessary lookup if we can help it -- so we'd want to figure out from the |
Hmm.. I feel like analyzing update operators is like the opposite of how I'd rather be spending my time. Is it really that bad to just do the denormalization in the methods directly rather than inside |
Yeah the problem with putting it in methods is that it's spread all over the place. But maybe an intermediate solution is for the method to call |
Yeah and it could perhaps pass the new value of the field, since that will be clear from the method body. |
This works for me as a solution for now anyway. Want me to change it? |
yeah, although I'm not sure if |
Oh, so what I meant was something like Lists.methods.makePrivate = new Method({
run({ listId }) {
...
Lists.update(listId, {
$set: { userId: this.userId }
});
Lists.userIdDenormalizer.set(listId, this.userId);
}
}); |
(An conceivably if another method set the |
Yeah that looks awesome. |
So I guess the burden on the developer would be:
Shouldn't be too bad, I think? |
Yeah. I mean it's not as nice as putting it on the mutator, but it's not bad. And if someone makes a bulletproof denormalizer package, then I guess we can go back to it. |
The method pattern means at least you know where to look! |
So that we can do better authorization and avoid fetching the List for every todo operation.
The text was updated successfully, but these errors were encountered: