Giter Site home page Giter Site logo

Comments (15)

mitar avatar mitar commented on June 18, 2024

Yes, I think it should work to the same extend it works in non-reactive publish. But I am not sure if works there as you would expect (merging fields from multiple cursors). I think it works that the last published document version wins.

Now that I think, are you sure that works even in non-reactive publish?

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

Meteor docs says it doesn't work in non-reactive publish, but it does seem to work in other reactive publish packages. Maybe its just the last published document that wins in all packages - as you say. I'll check it out.

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

lepozepo:reactive-publish supports returning multiple cursors from the same collection, but I am trying to find a replacement because it has issues with meteor 1.2.
but this library acts like the meteor core publish function in that it doesn't support returning multiple cursors from the same collection.

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

but this library acts like the meteor core publish function in that it doesn't support returning multiple cursors from the same collection.

What happens if you try to do that?

And yes, I think it is ill defined the behavior if you return multiple cursors from the same collection, so I do not it is really a good direction to try to support that?

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

I have found a way to split my publications so that they no longer return multiple cursors per collection in any individual publication. Meteor docs says that in this case, it will merge the results of multiple subscriptions, and it does.
I will leave this as an enhancement request for your package, and I'll open a separate ticket for my current reactive issues with your package.

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

Yes. Meteor merges per top-field. But be careful, if two publications publish the same top-field for the same document, then there is no defined order in which Meteor will choose the top-field. Often it does not matter (the value of the top-field is the same) though.

I do not think it is a viable feature and it is a known limitation that you should not be publishing the same collection multiple times (it is even documented in warning), so I will for now leave this closed. If somebody makes a simple pull request which makes it work, I would consider it. My main issue is that it is unclear what would be a good semantics. Merging fields together?

Hmm. Now that I am thinking, maybe there is a reasonable approach. Do you know how to test a branch if I make one? We could remember which fields are published with added, not just which documents, and then just at the end of the computation run remove those fields which were not added this time. But otherwise we would simply stack them together (which we can do because we in fact simply call changed instead of added anyway).

BTW, you can publish multiple collections by returning them in multiple autorun:

Meteor.publish('foo', function () {
  this.autorun(function (computation) {
    return Post.find({foo: 1});
  });
  this.autorun(function (computation) {
    return Post.find({foo: 2});
  });
});

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

Thanks for your input. Meteor seems to merge the fields of matching docs. This is particularly handy for my use case where I am pulling different fields based on the user's role. Though I shouldn't need it now in your publish as I have split them into separate publications now.

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

BTW, why don't you build the fields in advance and then do only one query?

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

i need different fields from different records of the collection based on their relationship - for privacy reasons.

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

Yes, but you could compute which fields you need once, no? Can you show me an example?

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

This is a sample of what I was using in meteor 1.1 which was working for me using lepozepo:reactive-publish

Meteor.reactivePublish('family',function() {
  return [
    Family.find({ownerId:this.userId}),
    Family.find({ownerId:{$in,related(this.userId)}, private:{$ne:true}})
  ]
}

related() is a function that computes the ownerIds of relatives of the current user. The current user is not permitted to see docs marked private by other users.

lepozepo's package worked great in 1.1, but crashes in 1.2 (with no method 'onStop') - which is why I tried your package instead.

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

So why don't you do:

Meteor.publish('family', function() {
  this.autorun(function (computation) {
    return Family.find({$or: [
      {ownerId: {$in: related(this.userId)}, private: {$ne: true}}
    ,
      {ownerId: this.userId}
    ]});
  });
});

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

So I do not think there are many use cases where you would need to publish multiple cursors for the same collection. I think you can always convert it to one query. And it is probably even more efficient so.

So I implemented a check which currently prevents publishing multiple cursors for the same collection name.

from meteor-reactive-publish.

dpatte avatar dpatte commented on June 18, 2024

Thanks for showing me the merged query. I'm not sure how to convert it to one query when requesting different fields, though. I do have a few of those which I have split into separate publications.

from meteor-reactive-publish.

mitar avatar mitar commented on June 18, 2024

OK, so, this prevents things only when you are returning cursors and are expecting the publish framework to publish those cursors. You can always observe cursors yourself and do whatever you want. :-)

from meteor-reactive-publish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.