Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publications are leaking(!) to other routes for current user #52

Closed
v3rron opened this issue Aug 8, 2015 · 1 comment
Closed

Publications are leaking(!) to other routes for current user #52

v3rron opened this issue Aug 8, 2015 · 1 comment

Comments

@v3rron
Copy link

v3rron commented Aug 8, 2015

I have two publications:

Meteor.publishComposite('allPostsWithComments', {
  find: function(){
    return Posts.find({"status.deleted": false}, POST_OPTIONS);
  },
  children: [
    {
      // find related post owner
      find: function(post, activity){
        return Meteor.users.find({_id: post.user_id }, USER_OPTIONS );
      },
    },
    {
      // find related post comments
      find: function(post, activity){
        return Comments.find( { post_id: post._id, "status.deleted": false } );
      }
    },
  ]
});
Meteor.publishComposite('onePost', function(postId) {
  return {
    find: function() {
      // Find posts made by user. Note arguments for callback function
      // being used in query.
      return Posts.find({ _id: postId }, POST_OPTIONS);
    },
    children: [
      {
        find: function(post){
          // publish post owner
          return Meteor.users.find({_id: post.user_id}, USER_OPTIONS);
        },
      },
      {
        find: function(post){
          // publish post comments
          return Comments.find({post_id: post._id, "status.deleted": false});
        },
        children: [
          {
            find: function(comment, post){
              // publish users related to comments
              return Meteor.users.find({_id: comment.user_id}, USER_OPTIONS);
            }
          }
        ]
      }
    ]
  }
});

And two routes:

this.route('explore', {
  waitOn: function () {
    // return one handle, a function, or an array
    return [
      subsManager.subscribe('allPostsWithComments'),
    ];
  },
});
this.route('postShow', {
  path: '/post/:_id',
  waitOn: function () {
    return [
      subsManager.subscribe('onePost', this.params._id),
    ];
  },
  data: function () {
    return { post: Posts.findOne({_id: this.params._id}) };
  },
  yieldRegions: {
    '_postOptions': {to: 'options'},
    '_headerBack': {to: 'header'},
    '_newCommentFooter': {to: 'footer'},
  },
});

As you can see in this scenario in "onePost" publication I'm not filtering posts by "status.deleted: false". That's because I want to publish deleted post only to "postShow" route and if it's deleted, I'm showing manual message to user: "This post has been deleted".
But I do filter by "status.deleted: false" on "explore" page as you can see in "allPostsWithComments" publish.

Now here's the problem: when I delete the post in "postShow" page, it's showing correctly deleted message and redirects me back to "explore" page and the currently deleted post is shown there and in all other routes as well for my current user until I hit refresh in my browser!. It's working normally for other users and the post disappears from their "explore" page when it's getting deleted. It's also working normally for my current user only after I hit refresh page.

PS: I tried navigating with Iron Router through both Router.go() and <a href="/explore"></a> and result is the same.

@v3rron v3rron changed the title Publications are leaking to other routes for current user... Publications are leaking to other routes for current user Aug 8, 2015
@v3rron v3rron changed the title Publications are leaking to other routes for current user Publications are leaking(!) to other routes for current user Aug 8, 2015
@v3rron
Copy link
Author

v3rron commented Aug 8, 2015

I actually figured it out. :) It turned out to be subsManager package which was basically caching the subscriptions on the client.
Just needed to change from subsManager.subscribe('onePost') to Meteor.subscribe('onePost') and everything works like a charm.

@v3rron v3rron closed this as completed Aug 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant