Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer special field projection $ #198

Open
theodorDiaconu opened this issue Nov 8, 2017 · 0 comments
Open

Offer special field projection $ #198

theodorDiaconu opened this issue Nov 8, 2017 · 0 comments

Comments

@theodorDiaconu
Copy link
Contributor

Meteor doesn't currently support this, but we can do it.

Problem

Collection.find(teamId, { fields: { name: true, users: { $elemMatch: { _id: this.userId } } } });
AnotherCollection.find({ 'sharedByUrl.hash': hash }, { fields: { title: true, 'sharedByUrl.$': true } });

This type of projection only returns you the first field it finds that matches the solution. This looks like a very useful thing to have.

Solution

We need to do the following:

Exclude the ObservableCollections that contain special fields projection from the initial find if and only if a projected field has changed. In the example above if:

  1. "users" - changed ($addToSet, $pull, $remove)
  2. "sharedByUrl.hash" - changed (we strip down ".$." when sending modified fields, if you do an projected update)

When a processor is dealing with this type of ObservableCollection, it needs to do a proper fetch for that element id with the proper projection. (The old way of doing things)

Implementation

In the RedisSubscriptionManager we need to split redis event handling into 2 phases, we process the same way the observableCollections that don't have special field projection. The other ones need to pass an extra argument to the processor (called preFetch) and pass doc as a simple {doc: {doc._id}}

Make sure to only fetch it with things that have changed, not all the fields we currently have.

Conclusions

This may feel like bloating a bit the code, but it's something very important and often used and we should treat it as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant