I’m mostly finished with a new Meteor app for a client. My first Meteor app in a number of years. Man, I forgot how I used to love Meteor. I still do. The app is looking fabulous, client happy, all that. Using React.
So I hit this weird area, building this component that displays a number of cards to the user. Each card has some enrollment data on it for individual camp information (the client is a music camp that enrolls participants). The January card has data for that camp, the March card had data for it, etc. 16 camps in all. The client wanted this info real time because they get inundated with enrollments at certain times and it was important to have the enrollment numbers up-to-date as people are enrolling.
My original thought was that this component could get slow, but it turned out OK. It’s read-only data, not changeable by the user.
So, the publication is simple enough. It’s publishing the last two years of camps in the ‘programs’ collection.
In the component, within the componentDidMount, I have the subscription with the Tracker.autorun().
Meteor.subscribe('programs', () => {
this.MayiTracker = Tracker.autorun(() => {
const mayi = Programs.find({ CampYear: 'mayi19', Week1: '0'}).fetch();
...
...
});
this.JuniTracker = Tracker.autorun(() => {
const sepi = Programs.find({ CampYear: 'sepi19', Week1: '0' }).fetch();
...
...
});
...
...
})
componentWillUnmount() {
this.MayiTracker.stop();
this.SepiTracker.stop();
...
}
At this point I was aware that although I was stopping the Trackers, I wasn’t sure if the subscription call would be stopped by default. Would I have to stop it manually as well?
Anyway, everything working as expected. Cards loading data pretty quick (about 3 seconds in production environment) considering the number of sockets that had to open. But then someone reminded to me that I had the separate Trackers within the subscription call. I had remembered it backwards.
So I got busy reversing them, putting the separate subscriptions and Mongo queries inside one Tracker.
this.IntermezzoTracker = Tracker.autorun(() => {
Meteor.subscribe('programs', () => {
...// Mongo query, etc.
...
});
Metero.subscribe('programs', () => {
...// Mongo query, etc.
...
});
});
Alrighty then. Redeployed online to test again. But data loading into the cards was at least twice as slow. 7 to 8 seconds to get the cards loaded with data. The way I had it before was far superior in terms of getting the data loading on the UI.
Can any of you Meteor Monsters out there fill me in on what’s going on? If the first way is used, is stopping each Tracker all I need to do on un-mounting? Why is the second way so much slower?
Much appreciated. And long live Meteor.