1

I am writing an app that involves creating multiple subsets of the same collection, and publishing them under different record sets following this example.

Using this principle, I am creating ad hoc record sets. The publish code is in a method that gets called per template:

//Template
Template.item._item = function() {
    Meteor.call('publishMethod', foo);
    Meteor.subscribe('name-'+foo);
    return someFunction(foo);
}

//Method
Meteor.methods({ 
    'publishMethod' = function(foo) { 
        Meteor.publish('name-'+foo, function() { someFunction(foo); });
     });
});

//Common area
someFunction = function(foo) {
    return Collection.find({'foobar' : foo});
}

In this example, someFunction() sits in common area between client and server. someFunction() returns a subset of a collection based on foo.

I have some questions regarding the above approach:

  • When a method is called with the same foo value, Meteor prints "Ignoring duplicate publish named 'name-foo'". Is there any way to check if a record set exists?
  • There is concern that these record sets will continue to be published and not release memory. Are these record sets client side only? Or will they accumulate on the server?

This is the best approach I have found for dealing with multiple, complex queries on the same large dataset, and allows for specific fields to be sent per request and page. I am however open to suggestions.

Thanks in advance.

Community
  • 1
  • 1
kyleredon
  • 63
  • 1
  • 7
  • Have you had a look at the example at meteor docs: http://docs.meteor.com/#publish, there is an example that shows how to use variables in your publish and subscribe functions, It's probably not the best design to call subscriptions from template helpers or publish within methods – Tarang Mar 15 '13 at 14:24
  • Publish/subscribe don't need to be called over and over -- you set them up once and this establishes a contract between client/server to pass along changes to data. When data comes in to the client, the reactivity kicks in and templates update. If you want some insight on publishing different "views" of the same collection, take a look here: http://stackoverflow.com/questions/12223866/meteor-publish-subscribe-strategies-for-unique-client-side-collections/13076752#13076752 – matb33 Mar 15 '13 at 15:21

0 Answers0