Awesome. That would make a lot of sense.
I have a question. If I were to limit all my queries on the server, to (say) 12 results, how would I be able to retrieve an arbitrary document by ID? It seems like the limit would prevent me from returning any document that was further down the list?
You can do this in two ways:
- Use a Meteor method to retrieve single documents by ID. This may be the easier solution, as long as you can call the method at the “right time”.
- Leverage Meteor’s pub/sub. Publication#1 limits the result set to 14. Publication#2 publishes a single document by ID. On the client, subscribe to both publications. Meteor will ensure you get the merged result.
Thank you, those sound like just what I need. I’ll have a go.
Here are some notes on the changes I’ve made recently, in case it helps anybody else. All these things are pretty basic but I hadn’t thought about them enough in my focus on the front end.
Pagination: Alethes Pages
It seems this package publishes ALL fields of paginated collections. Not only does this hit the database but it means that if you show a paginated list of users, all their sensitive information such as emails is shown. I have removed the Users page while I try to find out whether there is any way to limit the published fields, or a better pagination package to use.
I’ve also been much more careful about where the pagination is used. My Home page shows the first few documents in each category (New Documents, My Documents, All Documents, Recently Viewed) and I’ve created a separate publish function on the server for each, taking care to return only as many documents as required and only the fields that will be displayed.
The Pagination is now only used for the subsidiary pages that show a paginated view of New Documents (or whatever). These pages are still expensive but cleaning up the Home page (the most commonly viewed page) should help.
The search index has to access all documents and users, but I’ve limited the published fields to those that are searchable.
Generally I’ve trawled through all my publish and subscribe functions, trying to make sure they are as parsimonious as possible.
Oplog tailing would probably still be a good idea, but I think it was well worth cleaning up my database use first. I’ll run the app for a bit and see how it goes before making more changes.
Thanks again for all the help!