-
Notifications
You must be signed in to change notification settings - Fork 305
Data Loading and Management #33
Comments
@justinsb This would possibly be a chapter you might want to weigh in on. I'll ping you again when it's more fleshed out. |
See also #11 |
So for me the most important thing I tell new people who start with Meteor is a cycle of data propagation you have to keep in mind:
So I think it is really important that people understand that they should not be changing data or templates directly on the client but should go through the server and leave to the loop to make everything happen. What about where should publish functions go? This is for me still unclear. Should it be separate from views? Or together with views (so in same directory, where view for me is close to feature)? Because some publish functions are shared between views and some are not. Same for methods. Same you need for a particular view and some are generic. |
I think we should take a look at @arunoda's subs-manager and see if there is some low-hanging fruit we could suggest there.
Technically, webhooks will be calling a method, but conceptually they are about data loading. I guess the pattern is, use the webhook to insert into Mongo?
So is a subscription for one document where you pass the single document not a good idea? |
Subs manager is good for what it is but I think decided we aren't comfortable recommending that technique because of the scope for bugs given Meteor's current globalness. I could reconsider that.
I thought webhooks are about data modification? So the forms chapter would make sense. The only issue is that it's about "forms" rather than "methods" right now. But I think that's still OK
I think an |
I think what @mitar is saying about a sort of "flow diagram" of how data moves around is hugely useful. My only question is which article does this "fluxy" diagram go in? This one or the methods one? |
@tmeasday could you tell more about the issue with subsManager? It gives significant performance and UX improvements. |
@arunoda the issue that always concerns me is bugs which are hard to replicate. The subs-manager pattern introduces a second layer of state in the app which is "where I was a little while ago". All of a sudden the data that's in your local cache is no longer determined but just where you are now, but also where you were for the lifetime of the subs manager cache. If people were always super careful in their find calls to just select the documents and fields that they subscribed to, it wouldn't be a problem, but they aren't (not-withstanding heroic attempts by people like @SachaG to promote patterns to ensure it). It's true that the above is the real problem, and things like page->page transitions suffer the same issue (two sets of subscriptions open at once and rendered to the screen separately). But the difference there is that it's much more obvious what the issue is when something goes wrong. In the subs manager world, it's easy to imagine scenarios where people have bugs reported that they can't replicate (because the true replication is "first go to page A, then go to B and do a bunch of stuff"). If you could do something like Am I being overlay pedantic here? Maybe! But I'm worried about recommending patterns that I personally avoid.. Oh, and btw, I'm not sure it's fair to say it gives significant performance improvements. I can imagine both cases where it would help performance (not repeatedly re-opening the same pub) and hinder performance (leaving unnecessary and expensive publications open for extended periods of time). |
Okay I get it. I'm pretty okay with it's not in the here. Just my idea. May be we need to define different areas in the Meteor guide. Which tools suites in which place and so on. Anyway, eventually users will findout SubsManager. Performance GainsIt gives huge performance boost. That's due to a lot of practical scenarios. About the performance gains subsManager gives you in two ways.
This reduce subRate of the app a lot. It's safe to assume users browse the same page(areas) a lot time in a single session. So, that reduce the all the re-subscribing and CPU costs goes to network activities (and transport related code in Meteor) Our tests shows, most of the apps have subscriptions with very low lifetime. And changes in those subscriptions are very little. (compared with the time it's open). And Meteor reuses observers. Out tests shows many of the apps have over 50% obeserver reuse ratio. So keeping the subscription open is not an issue And we don't ask to add subsManager for every subscription. It's upto users to decide which subscriptions powered by SubsManager. We mentioned this in BulletProofMeteor and in Kadira docs. |
Ok, it's fair to say that for a subscription that is often/usually shared it does give significant performance gains. I think if we don't include it, this is a clear case of a package that should be mentioned in a "further reading" section of this article. I'll wait for @stubailo to weigh in again. |
@tmeasday That's sound great. SideNote: I assume this is discussed somewhere else, it's good idea to have different sections for people with different levels of understanding. Or we can narrow the first release for some generic guidelines. |
You mean this ticket? #2247 So maybe instead of |
More or less, yeah.
Nope..
"X" is to database what cursor is to collection. Agree that "dataset" isn't a great word but it does seem to work. |
Or did you mean Java background because I put |
:-) |
The question is what are operations you can do on X? So first probably select a collection, then query? I think better API would be that you could do:
where |
I'm not against that, but I have other plans around slicing up the datasets and using them as "contexts" for templates/components. You might call it Relay or something like that. (That makes me think, what does Relay/GraphQL call this concept..) |
Anyway, it's all pretty academic because a client-side merge box is a highly non-trivial change so I don't expect we'll see it any time soon. |
I don't know about you, but with my proposed API this is as easy as:
Of course that behavior of using queries inside template instances context could be done even automatically, that it takes all template subscriptions as context.
You would like to limit fields based on the subscription? They yea, it is tricky. But just getting which IDs are from which subscription is probably already available somewhere internally. |
Incorrect. You can use https://atmospherejs.com/percolate/find-from-publication to fake it, but it's a total kludge. |
BTW, what you |
If we are talking proposed APIs, mine would look something like <template name="fooController">
{{> foo instance.dataset}}
</template> Template.fooController.onCreated(() => {
this.dataset = this.subscribe('foo').dataset();
});
Template.foo.helpers({
posts: function() {
return this.dataset.posts.find();
}
}); Then it is trivially easy to test |
I like it. To do this, we need to remove the mergebox from the server. On Wed, Oct 28, 2015 at 11:05 AM Tom Coleman [email protected]
|
OK, this API is really the same as mine, only that it is prefix instead of suffix. And that it has big problems because of the reactivity. What if I publish first one collection and then after some time (after ready) I publish another. You would at least have to have |
@arunoda 👍. This is the direction that @stubailo were talking in, something like: Posts.all = new Subscription({
query: () => { ... }
});
const handle = Posts.all.subscribe('foo'); Which could then totally do the dataset pattern via re-running the query client side. But then the question is how to make the publication work properly with queries over multiple collections -- do you map it to publish-composite syntax or something? Doesn't sound completely impossible but a big chunk of concepts that we'll leave for the next iteration of the guide if we still like it. (Thus my original comment) |
I would rephrase heading c like this:
And I would add:
where there could be pointers to more advanced solutions, such as reactive-state. |
Huh, opaque strings for keys in the state. This is not very IDE friendly. ;-) |
@steph643 thanks for the link. I guess this reactive state idea is sort of angular-like, no? -- A tree of "state" (aka scope) that you use within a template. I guess what I don't like about it is that if it's going to be tree like it makes sense to scope it to the relevant branch of the template heirarchy rather than letting the template be in charge of grabbing something global itself. |
I really think such solutions should be third party packages. Blaze should provide template instances, and then people can attach react-like props, Blaze Components like fields, angular like state to it. We will hardly decide which one is the best. :-) |
Thankfully the ReactiveDict approach isn't a package - it's just one suggested pattern. If people decide that ReactiveDict doesn't fulfill their needs, it will be easy to switch to something else and have basically the same patterns. |
Yes, I am talking about some old ideas of making
Should we suggest all of them? Using ReactiveDict, ReactiveField, and reactive state? :-) That can be like a very short sections, three headings, three should examples, and then it can continue with whatever direction you want the rest of the guide to use. |
I made this package which allows one to scope queries to the subscription. I decided to do a different API to the one above. |
Interesting. A few notes in comparison to FFP:
|
@tmeasday what's FFP? |
Oh, find-from-publication (the package that subscription scope is replicating with a different approach and API) |
Okay got it :) |
That you are using two collections/subscriptions. So both have to be on the client up-to-date to be able to query based on the subscription, no? So if I do
I have not measured things over the wire, true. So maybe this is premature optimization on my part. But, it does increase memory on the server-side because merge box stores all those documents.
Yes, I could do sorting, but I didn't want to because the server side becomes really complicated then (you have to use observe with What use cases you have for an example of where the order of calling
I am not saying that it is nice, but it is simpler, less lines of code, less data to go over, simpler concept. Meteor should provide APIs to do that properly. @rclai is now working on at least common API for something like this: https://github.com/rclai/meteor-collection-extensions But I think that Meteor's common way is to not provide APIs until community develops package showing the need for that. But yes, please do merge this pull request in: meteor/meteor#5845 BTW, you might be interested in this package as well: https://github.com/peerlibrary/meteor-subscription-data |
I'm thinking about any time the sort order is not knowable on the client. For instance if you query a fulltext search endpoint (think ElasticSearch) to get a ranked set of documents for the publication. |
Interesting stuff, thanks for showing me @mitar |
You can just pass that extra score to the client in that case. See the example here: https://github.com/peerlibrary/meteor-subscription-scope |
Well sure if you are ok about adding extra fields to the document. What I was thinking about was something similar to what you've done where the extra field is stripped somehow before coming back out to the query-er |
Yes, but that score field is something you might even want to display to the user. Anyway, those are details. I am explaining my rationale. :-) As you noticed, it is something easy to change. And also I on purpose on the client side check only for existence of the field so that in theory we can add any extra payload. |
Article outline
https://github.com/meteor/guide/blob/master/outlines/data-loading.md
Major decision points
publish-composite
Old outline:
Proposed outline
Open Questions
The text was updated successfully, but these errors were encountered: