0

I combined two of my publications into a single one, as they were very similar. Both of them returned a set of cursor. I've rewritten them in low-level API, in order to make some control on data removing.

My problem is that, for a reason I totally ignore, the subscription onReady callback is never triggered. I've got other low-level pubsub in my app which publish data in a similar way and that works perfectly.

On the server, all my logs are correctly displayed, and no error is shown. The publication is runned correctly and the data are effectively sent to the client. On the client, none of the onReady or onError callback is triggered.

Publication :

Meteor.publish("getTalkthread", function ( thread_id ) {
  unblock(this);

    console.log("start");

  let uids = tags = corrections = [],
            self = this;

    let posts_cursor = Modules.both.queryGet({
                type                : 'posts',
                method          : 'find',
                query               : { $or: [
                            { _id: thread_id },
                            { parent: thread_id }
                          ]
                        },
                projection  : { sort    : { _id: 1 },
                                                limit   : 50
                                            }
            });

  let posts_array = posts_cursor.fetch(),
      posts_ids = posts_array.map( e => ( e._id ) );

    //console.log("fetched posts", posts_array);

  let corrs_cursor = Modules.both.queryGet({
                type                : 'corrections',
                method          : 'find',
                query               : { talkId: { $in: posts_ids } },
                projection  : { sort    : { _id: 1 },
                                                limit   : 50
                                            }
            });

  let corrs_array = corrs_cursor.fetch();

    //console.log("fetched corrs", corrs_array);

  let posts_authors = posts_array.map( e => ( e.owner ) ),
      corrs_authors = corrs_array.map( e => ( e.owner ) );

  let users_ids = _.union( posts_authors, corrs_authors );

  let users_cursor = Modules.both.queryGet({
            type                : 'users',
            method          : 'find',
            query               : { _id: { $in: users_ids } },
            projection  : { sort        : { date: -1 },
                            limit       : 100,
                            fields  : USER_PROFILE_FIELDS_
                        }
        });

    //console.log("fetched users", users_cursor.fetch());

  let observers = {};

  observers.posts = posts_cursor.observeChanges({
        added       : ( id, fields )    => { console.log("post added " + id); self.added  ("posts", id, fields); },
        changed : ( id, fields )    => { console.log("post changed " + id); self.changed("posts", id, fields);  },
        removed : ( id )                    => {
            console.log("test");
      if ( id != thread_id ) {
                console.log(true);
        self.removed("posts removed " + id);
      }
    }
    });

    observers.users = users_cursor.observeChanges({
        added       : ( id, fields )    => { console.log("user added " + id); self.added  ("users", id, fields);    },
        changed : ( id, fields )    => { console.log("user changed " + id); },
        removed : ( id )                    => { console.log("user removed " + id); }
    });

  observers.corrs = corrs_cursor.observeChanges({
        added       : ( id, fields )    => { console.log("corr added " + id); self.added  ("corrections", id, fields);  },
        changed : ( id, fields )    => { console.log("corr changed " + id); self.changed("corrections", id, fields);    },
        removed : ( id )                    => { console.log("corr removed " + id); self.removed("corrections", id);                }
    });

    console.log("observers created");

    this.ready();

  self.onStop( () => {
        observers.posts.stop();
        observers.users.stop();
        observers.corrs.stop();
    });

    console.log("end");

});

Subscription :

      console.log("sub");
      self.subscribe("getTalkthread", id, self.rerun.get()), {
        onReady: function () {
          console.log("READY");
          if ( !Posts.findOne({ _id: id } )) {
            $("#404NotFound").show();
            $("#isoContent").hide();
          } else if ( Posts.findOne( id ) ) {
            $("#isoContent").show();
          }
          $("#spin").hide();
        },
        onError: function () {
          console.log("ERROR");
          $("#spin").hide();
          $("#404NotFound").show();
          $("#isoContent").hide();
        }
      };

The client page is correctly rendered, but the DOM manipulation are not triggered, forbidding the display of the content. Does anyone see what I'm doing wrong here ?

Thanks you

EDIT:

I tried to return an array of the three cursors, and, for whatever reason, the problem is the same. However, I don't see why.

4

1 回答 1

0

虽然我不明白为什么,使用 Arunoda 的 SubsManager 而不是本机 Meteor.subscribe 解决了这个问题。

于 2016-05-10T16:00:47.343 回答