All Projects → peerlibrary → meteor-control-mergebox

peerlibrary / meteor-control-mergebox

Licence: BSD-3-Clause license
Control mergebox of publish endpoints

Programming Languages

coffeescript
4710 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to meteor-control-mergebox

hypersubs
an upgraded version of Meteor subscribe, which helps optimize data and performance!
Stars: ✭ 13 (-53.57%)
Mutual labels:  meteor, meteor-package, ddp
meteor-subscription-scope
Scope queries on collections to subscriptions
Stars: ✭ 20 (-28.57%)
Mutual labels:  meteor, meteor-package, ddp
Meteor-flow-router-title
Change document.title on the fly within flow-router
Stars: ✭ 23 (-17.86%)
Mutual labels:  meteor, meteor-package
unity3d-ddp-client
Lightweight DDP client for Unity3D
Stars: ✭ 18 (-35.71%)
Mutual labels:  meteor, ddp
ostrio-analytics
📊 Visitor's analytics tracking code for ostr.io service
Stars: ✭ 14 (-50%)
Mutual labels:  meteor, meteor-package
Meteor-Cookies
🍪 Isomorphic bulletproof cookie functions for client and server
Stars: ✭ 41 (+46.43%)
Mutual labels:  meteor, meteor-package
Client-Storage
🗄 Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
Stars: ✭ 15 (-46.43%)
Mutual labels:  meteor, meteor-package
flow-router
🚦 Carefully extended flow-router for Meteor
Stars: ✭ 191 (+582.14%)
Mutual labels:  meteor, meteor-package
Meteor-Template-helpers
Template helpers for Session, logical operations and debug
Stars: ✭ 35 (+25%)
Mutual labels:  meteor, meteor-package
meteor-reactive-mongo
Reactive server-side MongoDB queries
Stars: ✭ 14 (-50%)
Mutual labels:  meteor, meteor-package
meteor-two-factor
🔐 Two factor authentication package for accounts-password
Stars: ✭ 80 (+185.71%)
Mutual labels:  meteor, meteor-package
Meteor-Mailer
📮 Bulletproof email queue on top of NodeMailer with support of multiple clusters and servers setup
Stars: ✭ 21 (-25%)
Mutual labels:  meteor, meteor-package
meteorman
A DDP client with GUI (The Postman for Meteor)
Stars: ✭ 51 (+82.14%)
Mutual labels:  meteor, ddp
meteorpp
Meteor DDP & Minimongo implementation in C++.
Stars: ✭ 22 (-21.43%)
Mutual labels:  meteor, ddp
react-meteor
Meteor Reactivity for your React application, inspired by react-native-meteor.
Stars: ✭ 16 (-42.86%)
Mutual labels:  meteor, ddp
meteor-devtools-evolved
The Meteor framework development tool belt, evolved.
Stars: ✭ 146 (+421.43%)
Mutual labels:  meteor, ddp
blaze-integration
Vue integration with Meteor's Blaze rendering engine.
Stars: ✭ 24 (-14.29%)
Mutual labels:  meteor, meteor-package
meteor-computed-field
Reactively computed field for Meteor
Stars: ✭ 18 (-35.71%)
Mutual labels:  meteor, meteor-package
Meteor-logger-file
🔖 Meteor Logging: Store application log messages into file (FS)
Stars: ✭ 24 (-14.29%)
Mutual labels:  meteor, meteor-package
Meteor-logger-mongo
🍃 Meteor Logging: Store application log messages in MongoDB
Stars: ✭ 20 (-28.57%)
Mutual labels:  meteor, meteor-package

control-mergebox

UPDATE: This is now available in Meteor core.

This Meteor smart package extends publish endpoints with control of the mergebox for a given publish endpoint function.

Publish function's this is extended with this.disableMergebox() which when called will disable mergebox for current publish endpoint.

By disabling mergebox one chooses to send possibly unnecessary data to clients (because they already have it) and not maintain on the server side images of clients' data, thus reducing CPU and memory load on servers.

Server side only (with compatibility changes on the client side).

Installation

meteor add peerlibrary:control-mergebox

Discussion

This package disables storing the image of client's data on the server side for a given publish endpoint. This is useful to reduce CPU and memory load on servers, but it makes server unable to do some things it could do before:

Server does not know which fields client already has and what are their values, so if your publish function, for example, calls this.changed('collectionName', id, {foo: 'bar'}) twice in a row, server will not suppress sending the change twice. This is not so problematic because it keeps the semantics unchanged, just makes more data go over the wire.

Server also does not know which documents were published from which subscription. This is more problematic. With mergebox, Meteor tracks which subscription published which documents (with which fields) and if a document with same ID (and with possibly overlapping fields) is published from multiple subscriptions, Meteor knows what to do when one subscription removes a document (or a field) which still exists in other subscriptions. It removes just the fields previously published by this subscription only, while keeping all other fields for the document published. With disabled mergebox, when one subscription removes a document or a field that change is propagated immediately to the client as it is. This is different semantics to the one with enabled mergebox. So it is important to remember, with disabled mergebox, the last document or field change across all subscriptions is always the one propagated to the client side. There is simply no state in subscriptions anymore.

The default way to publish collections is to use observeChanges, explicitly or by returning a cursor from the publish function. This works well when server uses mergebox because only changes are really needed. But if you use multiple subscriptions over the same collection with disabled mergebox you might get strange results. For example, one subscription could remove a document (which would remove whole document on the client side) and then another subscription could change one field, which would result in document being re-added on the client side, but just with that one field. To improve this, one could use document-level observe:

Meteor.publish('myPublish', function () {
  var self = this;

  var handle = collection.find({}, {transform: null}).observe({
    added: function (newDocument) {
      self.added('testCollection', newDocument._id, _.omit(newDocument, '_id'));
    },

    changed: function (newDocument, oldDocument) {
      _.each(oldDocument, function (value, field) {
        if (!_.has(newDocument, field)) {
          newDocument[field] = undefined;
        }
      });

      self.changed('testCollection', newDocument._id, _.omit(newDocument, '_id'));
    },

    removed: function (oldDocument) {
      self.removed('testCollection', oldDocument._id);
    }
  });

  self.onStop(function () {
    handle.stop()
  });

  self.ready();
});

But the question is then how much overhead do you gain on the server by using observe instead of observeChanges, because observe has to cache documents.

In general it is advisable to not use multiple overlapping (in documents) subscriptions when disabling mergebox. Behavior is then predictable and matches the normal Meteor behavior.

Related projects

  • meteor-streams – allows sending of messages from server to client without a mergebox, but then requires manual handling of those messages on the client, not using features already provided by Meteor
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].