I have created two templates ( A and B).
A - Shows up when a user has not created documents in a certain Mongo collection.
B - Shows up if the user has created documents in the collection.
Essentially I am displaying a “Theres nothing here message” when no content exists.
To achieve this I use a helper to query mongo to check if documents exist. It looks like the following:
defaultCheck: function() {
var offerid = this.offerAccepted;
var id = Meteor.userId();
var result = Listing.find({
$or: [{
creator_id: Meteor.userId(),
status: "Completed"
}, {
offer_creator: Meteor.userId(),
status: "Completed"
}]
});
return Boolean(result.count());
}
So this returns a true or false Boolean value.
In my layout template I use #if to check the value of the defaultCheck
helper and either hide or show the A or B Template
{{#if defaultCheck}}
{{#each meetup}}
{{> ProfileActiveCard}}
{{/each}}
{{else}}
{{> DefaultProfileActive}}
{{/if}}
The Issue is that the query is too slow and the A template briefly shows up (flickers on and off) before the query completes.
How can I prevent this?