1
votes

I have a Meteor app which lists books. Clicking a book shows a list of its chapters and clicking a chapter shows a list of its comments. Now I'm trying to figure out how to optimize performance on the Meteor client.

My main concern is how I should structure my collections and if there is any way to let the server know what data to send first. I'm new to NoSQL but it seems that the correct Mongo approach is to let the chapters be subdocuments of a book and the comments subdocuments of the chapters.

However, I wouldnt want the client to have to wait until all chapters and comments are loaded into the client db just to show the list of books. I guess I could go with a relational db configuration but I am not sure if I can force Meteor to send the books table first or if using Meteor with a relational db would give me any other issues down the road.

Also, since I'm only transferring text, maybe this will not be much of a problem? Any suggestions appreciated!

2

2 Answers

2
votes

There are two principles you should keep in mind

  • you do not have to publish everything every time
  • it is the client who subscribes and this determines the order

in order to publish the list of books without the chapters you can use a query like this

Meteor.publish( "booksList", function () {
   return Books.find( {}, {fields: {bookName: 1}} );
} );

this should return a collection with only two attributes: _id and bookName

in a second publish you could send the whole thing but only for one book at a time:

Meteor.publish( "fullBook", function ( bookId ) {
   return Books.find( {_id: bookId} );
} );

on the client you should make sure to wait for the publish to have occurred before using the results.

This is all untested of course. I apologize in advance for the bugs.

0
votes

you should publish only necessary fileds.Otherwise your application will slow down reffer this link.