As I keep in mind, in order for us to have a real-time site and make changes to the database for all users at the same time,
Methods must also be entered in the client and defined in the client.
I did not enter these methods in the client, but I still see that the changes are done in real time for all users.
For example, if I create a post in one browser, it will be created quickly in another browser.
While the post creation method is not entered in the client.
Currently, when a change is made to the database in a browser, the change is sent to all clients.
I do not want the whole software to have this function. Because I think the bigger the software, the lower its performance because it takes more resources from the server.
āmake changes to the database for all users at the same time, Methods must also be entered in the client and defined in the clientā - this is a wrong statement.
Details are here: Methods | Meteor API Docs.
Meteor can use Optimistic UI. You would get the update on your client but not on the other clients.
That can only happen with techs like pub/sub, Streams. etc.
I believe your issue is related to a pub/sub. You could use a Meteor plugin for Chrome and see what subscriptions activate when you do various things. I would assume you already removed unsecure and autopublish packages.
hi ,
I made a small sample, please run this very small repository and open the application in two browsers.
In this example, when you create a new link, both your ui is rebuilt and the new link is displayed to you in real time, and also the ui of the other clients is rebuilt, and in fact the new link is displayed to them immediately.
This is while I did not enter the method that creates the new link in the client at all. And normally my ui should not be rebuilt and no new data should be sent to other clients.
Hey, Iām not sure if I got your question right because I was not able to open your repository but the fact that you havenāt imported the Meteor methods on the client side itās not related to having real time updates on different browsers.
When you import methods on the client what you have is optimistic UI, meaning that they will be simulated on the client and each user will get a quicker response because your logic will run on the client using minimongo before running on the server. When the method finish running on the server you get the real result of the operation.
Real time updates are the default way that Meteor works when you use publications and subscriptions.
@fredmaiaarantes
How to prevent all data from being real-time.
I just need part of the site to be real time.
I think if all the site with all its details is real time, it will be a heavy burden on the server.
And this time with the addition of users, even more
Use methods to load your data. I prefer this option.
Use Pub/Sub to load your data but you need to rewrite your publish function a little.
Instead of return the cursor, you call the function this.added to send data to client and this.ready() at the end.
I donāt say itās better in every cases.
For example when you go to a page, there is a react component there and in that component I call a method, it returns data I need. I donāt have ty select them from the mini mongo, I donāt care if I need to remove them after the component got unmounted.
But when I needed the data sits there for awhile. I would use pub/sub or I would insert them in local collections directly.
It depends on how your app works. There is no best option for all cases.
@fredmaiaarantes@storyteller
The problem with this method is that it is not compatible with ssr.
The react-router-ssr package works on a pub / sub basis.
As a result, no ssr is provided on pages where data is captured by methods.