Suppose I’m subscribed to 1000 items and 1000 itemRefs, and I have this code:
// ItemRefList Blaze component
Template.ItemRefList.helpers({
itemRefs(){
return ItemRefs.find();
}
});
<template name='ItemRefList'>
{{#each itemRef in itemRefs}} {{> Item itemId=itemRef.itemId }} {{/each}}
</template>
And this:
// Item Blaze component
Template.Item.helpers({
item(){
return Items.findOne(Template.instance().data.itemId);
}
});
<template name='Item'>
{{item.prop1}}{{item.prop2}}{{item.prop3}}{{item.prop4}}{{item.prop5}}
{{item.prop6}}{{item.prop7}}{{item.prop8}}{{item.prop9}}{{item.prop10}}
</template>
Now each time I request a prop on item the helper is fired and the minimongo needs to query the collection.
Would the following be more performant?
Template.Item.onCreated(function(){
var template = this;
template.autorun(()=>{
template.reactiveItem = new ReactiveVar(Items.findOne(template.data.itemId));
});
});
Template.Item.helpers({
item(){
return Template.instance().reactiveItem.get();
}
});
Any best practices for situations like this?