How does cursor.observe work and how to avoid running multiple instances?

Watch

I tried to understand how cursor.observe works inside a meteor, but found nothing about it. Docs says

Sets a live request that notifies callbacks whenever there is a change in the result of the request.

I would like to better understand what a live request means.

  • Where will my observer function be performed? Meteor or mongo?

Several runs

When we have more than just a user signing an observer, one instance is launched for each client, which leads to a performance and race condition problem.

  • How can I implement my observe to be like singleton ? Just one copy works for everyone.

Edit: There was a third question here, but now this is a separate question: How to avoid race conditions on cursor.observe?

+4
source share
1 answer

From the server side, from now on, observe works as follows:

  • Build a set of documents matching the query.
  • Poll the database with the query regularly and make the difference between the changes by emitting the appropriate events for callbacks.
  • When the corresponding data is changed / inserted into mongo by the meteorite itself, highlight the corresponding events, short-circuit step No. 2 above.

There are plans (perhaps in the next release) to automatically ensure that calls for a subscription that have the same arguments are shared. So basically taking care of the singleton part is automatic for you.

Of course, you could achieve something similar, but I think this is very important for the meteor team, so at the moment this is probably not worth the effort.

+8
source

Source: https://habr.com/ru/post/1442420/


All Articles