Meteor once or "static" publishes without tracking collection

Suppose you want to send the same collection of 10,000 documents to each client for the Meteor application.

At a high level, I know that the server performs some accounting for each client’s subscription, namely it monitors the status of the subscription so that it can send the appropriate changes to the client. However, this is terribly inefficient if each client has the same large dataset where each document has many fields.

It seems to have been a way to send a “static” post in explorer , where the original request was posted and was no longer modified. This seems like a much more efficient way to do this.

Is there a proper way to do this in the current version of Meteor (0.6.5.1)?

EDIT: as an explanation, this question is not about client side reactivity. This is about reducing server-side overhead for tracking client collections.

Related question: Is there a way to tell a meteor that the collection is static (will never change)?

Update: It turns out that doing this in Meteor 0.7 or earlier will lead to serious performance issues. See https://stackoverflow.com>

+4
source share
6 answers

http://docs.meteor.com/#find :

Statics.find ({}, {reactive: false})

Edited to reflect the comment:

Do you have information that reactive: false param is only client side? Perhaps you are right, this is a reasonable, perhaps interpretation. I don’t have time to check, but I thought it could also be a server-side directive, saying that I don’t poll the mongo result set. I want to know ...

You speak

However, this is horribly inefficient if each client has the same large data set where each document has many fields. 

Now we may discuss the effectiveness of the server code and its polling of the mongo source for updates that occur outside the server. Please ask another question, which is much higher than my ability to answer! I doubt that this happens once for each connected client, most likely this is synchronization between the application server information and the mongo server.

The client you request, including sorting, must be marked as inactive. It doesn’t depend on whether you can issue them using sorting instructions or whether they can be restarted using a different reactivity, but should not include a trip to the server. When each document reaches the client side, it is cached. You can still do your best to minimize opportunities. In the absence of updates, the client does not request the server, you do not need to disconnect it. The server clicks only if necessary.

+1
source

I think that using manual publishing ( this.added ) still works to get rid of the overhead created by the server by observing the data for changes. Observers must either be added manually or created by returning Collection.curser.

If the data set is large, you may also be concerned about the overhead of merging , which will store a copy of the data for each client. To get rid of this, you can copy the collection locally and stop the subscription.

 var staticData = new Meteor.Collection( "staticData" ); if (Meteor.isServer ){ var dataToPublish = staticData.find().fetch(); // query mongo when server starts Meteor.publish( "publishOnce" , function () { var self = this; dataToPublish.forEach(function (doc) { self.added("staticData", doc._id, doc); //sends data to client and will not continue to observe collection }); }); } if ( Meteor.isClient ){ var subHandle = Meteor.subscribe( "publishOnce" ); // fills client 'staticData' collection but also leave merge box copy of data on server var staticDataLocal = new Meteor.Collection( null ); // to store data after subscription stops Deps.autorun( function(){ if ( subHandle.ready() ){ staticData.find( {} ).forEach( function ( doc ){ staticDataLocal.insert( doc ); // move all data to local copy }); subHandle.stop(); // removes 'publishOnce' data from merge box on server but leaves 'staticData' collection empty on client } }); } 

update: I added code comments to make my approach more understandable. Meteorite documents for stop() in the subscription descriptor say: "This usually causes the server to send the client the deletion of the subscription data from the client’s cache," so there may be a way to stop the subscription (remove from the merge field), which leaves data on the client. This would be ideal and avoid the overhead of copying a client.

In any case, the original approach with set and flush also leave the data in the merge field, so maybe everything is fine.

+1
source

In addition, you could script to output the data to the js file as an array or object, minimize it, and then link it as a separate resource. See http://developer.yahoo.com/performance/rules.html to add an expiration or cache header. You probably don't want the meteor to bind it for you.

This will be the least traffic and can make subsequent downloads of your site much faster.

0
source

as an answer to the Meteor call, return an array of documents (use fetch ()). No reactivity or registration. On the client, create an impression when you execute the request, or extract the key from the session, and it responds to the client.

Mini mongo just manipulates js array / object with syntax interpreting dsl between you and your data.

0
source

A new quick rendering package makes publishing in the client collection possible.

 var staticData = new Meteor.Collection ('staticData'); if ( Meteor.isServer ){ FastRender.onAllRoutes( function(){ this.find( staticData, {} ); }); } 
0
source

As you have already indicated in googlegroups, you should use the Meteor method to send static data to the client.
And this neat package for working with methods without asynchronous headaches.

0
source

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


All Articles