performance - Is it worth batching subscriptions in Meteor? -
when displaying list of documents, can clearer write subscription @ document level (vs @ list level), in case template reused somewhere else instance. less efficient or meteor handling things magically?
more precisely, can put document logic in document template:
template.itemslist.helpers({ items: function() { return this.itemsids.map(function(id) { return { _id: id }; }); }, }); <template name="itemslist"> {{#each items}}{{> item}}{{/each}} </template> template.item.oncreated(function() { this.subscribe('item', this.data._id); }); <template name="item"> {{#if template.subscriptionsready}} ... {{/if}} </template>
or subscribe once documents @ list level:
template.itemslist.oncreated(function() { this.subscribe('items', this.data.itemsids); }); template.itemslist.helpers({ items: function() { return items.find({_id: {$in: this.itemsids}}); }, }); <template name="itemslist"> {{#if template.subscriptionsready}} {{#each items}}{{> item}}{{/each}} {{/if}} </template> <template name="item"> ... </template>
it looks second approach more efficient, since there 1 call subscription. if talking standard http requests here, there'd no doubt. since meteor socket based , handle lot of things under hood, wondering it worth trouble move logic away document list.
generally better call subscribe once. when run subscribe new params publish method re-runs, makes call db fetch needed documents , sends client. better , more efficient make 1 call db.
but makes sense if sure want display items , if there not many items in items
collection.
if there big number of items (hundreds or more) better kind of pagination avoid downloading documents client.
Comments
Post a Comment