Hi!
I’m facing an issue regarding performance with publications / subscriptions. Here’s the scenario:
I have two collections, connectors
and conversations
.
Both are published like that — so with an identifier and some fields.
Meteor.publish('conversations', function(id) {
return Conversations.find(
{ user: id },
{ limit: 1,
fields: {
user: 1,
action: 1,
messages: 1,
}
}
);
});
I’m subscribing on the client like that:
export default createContainer(() => {
const messageHandle = Meteor.subscribe('conversation');
const ready = messageHandle.ready();
let userId = Meteor.userId();
let conversation = Conversations.findOne({ user: userId }, { fields: { messages: 1, action: 1 } });
let messages = conversation ? conversation.messages : false;
let action = conversation ? conversation.action : false;
return {
messageHandle: messageHandle,
ready: ready,
messages: messages,
action: action
};
}, Messages)
When I log the arrival of a message:
incoming message Thu Oct 19 2017 16:53:20 GMT+0200 (CEST)
/* after the message was inserted into the db */
inserted message Thu Oct 19 2017 16:53:20 GMT+0200 (CEST)
But then, if you look at the client:
Where could those 8 seconds of delay come from? Note that this is the case, even if I completely wipe out the database, so it is not an issue of huge data amounts.
What I’ve tried so far:
- I added indices to the collections (should only matter for larger data though…)
if(Meteor.isServer) {
Connectors._ensureIndex({ "identifier": 1, createdAt: -1 });
Conversations._ensureIndex({ "user": 1, createdAt: -1 });
}
- I added listener’s that stop subscriptions on the client, when the component unmounts, or the window is closed. Would also be interesting if this is necessary, or it is taken care of in the background?
this.props.messageHandle.stop();
Other than that, I’m really running out of ideas — any help is appreciated