Dear Derby,
Having some struggles with what looks to me like a very basic pattern…
I have a wiki style app with a navigation bar to the left, and the document content to the right. For the navigation menu I need to know the names of all the documents. It would be good to know if these names change—and also if the pages disappear. Otherwise, I am not interested in their content.
However, currently “When fetching or subscribing to a query, all of the documents associated with that query are also fetched or subscribed.”. This seems to mean that the entire documents contents is fetched—it is also passed in the JSON generated on server-side render: I can read the contents of all pages on my wiki there! So while my originally imagined functionality is in place, the app is currently rather sluggish and I suspect this to be one of the reasons.
In the documentation I could not find, is there any method to exclude certain fields from a query?
Is there another way in which I can work around this problem?
I attached the code I used:
app.get(/^\/r\/(.*)/, function(page, model, params, next){
var slug = params[0];
// this is the document I want to display
var requestedDocument = model.query('documents', {'path' : slug});
model.set('_page.slug', slug);
model.set('_page.readMode', true);
requestedDocument.subscribe(function(err) {
if (err) return next(err); // 500
if (requestedDocument.get().length === 0) {
next(); // 404
};
var allDocuments = model.query('documents', {});
allDocuments.subscribe(function(err) {
if (err) return next(err);
// the following step is necessary because it is not 1 object, it is a list with 1 entry:
model.ref('_page.documents', requestedDocument);
model.ref('_page.document', '_page.documents.0');
// is there a smarter way to do this?
allDocuments.ref('_page.allDocuments');
page.render("read");
});
});
});
Thanks a bunch for your suggestions!
Eric