How can I control which data is synchronized with the Meteor client cache?

I modified the leaderboard example to use two collections:

Players = new Meteor.Collection("players"); Tasks = new Meteor.Collection("tasks"); 

The Players collection has 6 documents defined in the example.

 > db.players.count() 6 

The Tasks collection contains 48,000 documents.

 > db.tasks.count() 48000 

As soon as I open the browser, Node will switch to a 100% processor and the client will not be able to see any task entries.

 Players.find().count() 6 Tasks.find().count() 0 

I tried to determine the query criteria, but this only works on the server and does not help on the client.

 Players.find({name:"Claude Shannon"}).count(); 1 Tasks.find({tid:"t36254"}).count(); 0 

I assume that 48,000 documents are too much to sync. This leads to the fact that Node is bound to a 100% processor, and the client to such errors: http://i.imgur.com/zPcHO.png .

How to prevent the synchronization of everything and only get certain documents from the collection?

+6
source share
1 answer

Meteorโ€™s automatic publishing, which publishes all of your collections to the client, is very impressive and makes everything work fast, but it looks like the functionality of Rails for forests - not very useful for real applications - for training and prototyping.

By default, Meteor automatically publishes every document in your collection to every connected client. To disable this behavior, uninstall the package:

$ meteor remove autopublish

Then learn how to use the publish and subscribe functions manually, which offers you the control you need: http://docs.meteor.com/#publishandsubscribe

+18
source

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


All Articles