I have a design question about how best to get user data. I am displaying a list of reviews. Each review has a reviewer user id and a reviewee user id. The collection structure is like so:
{
"_id": 24235,
"reviewerId": 11254,
"revieweeId": 29981,
"rating": 5,
"reviewText": "Lorem Ipsum"
}
The blaze template needs to show the reviewer’s avatar and firstname. I am having trouble figuring out how best to get these details? Should I publish a service? I will be showing a list of reviews so the service will be called for each user, isn’t that inefficient?
<ul class="review-list">
{{#each reviews}}
<li>
<img src="{{reviewerAvatar}}"/>
<p>{{reviewerName}}</p>
<p>{{reviewText}}</p>
<span>{{rating}}</span>
</li>
{{/each}}
</ul>
Heres the idea I have but can the design be improved so I don’t make too many unnecessary requests for user details?
Template.reviewItem.helpers({
reviewerAvatar: function() {
// is it inefficient to make this call for both reviewerAvatar and reviewerName?
return Meteor.call('users.userDetails', this.reviewerId).avatar;
},
reviewerName: function() {
return Meteor.call('users.userDetails', this.reviewerId).firstName;
}
});