Meteor-Community-Packages/meteor-publication-collector

Error on stop with meteor-publish-performant-counts

nicocrm opened this issue · 2 comments

Hello and thank you for this package!

I get an error on line 37:

this.observeHandles.forEach(handle => handle.stop());
‣
Error: Cannot read property 'stop' of undefined
    at packages/johanbrook:publication-collector/publication-collector.js:37:47
    at Array.forEach (native)
    at PublicationCollector.<anonymous> (packages/johanbrook:publication-collector/publication-collector.js:37:29)
    at PublicationCollector.ready (packages/johanbrook:publication-collector/publication-collector.js:99:10)
    at PublicationCollector.collect (packages/johanbrook:publication-collector/publication-collector.js:53:10)
    at Test.<anonymous> (imports/projects/api/projects.tests.js:26:19)
    at run (packages/practicalmeteor:mocha-core/server.js:34:29)

The issue is caused by publishing a counter obtained using the meteor-publish-performant-counts package. This is my publication code:

Meteor.publish('PubName', function() {
    const cursor = collection.find({})
    const counter = new Counter('PubNameListCount', cursor)
    return [
      cursor, counter
    ];
})

I am not sure if this is because that package is not confirming to the subscription API, or because the publication-collector is relying on features that are not present in all publications. I did a little bit of investigation and I feel like it is the latter, but I am not that intimately familiar with the Meteor pub / sub mechanism yet so I could be missing something! Would there be interest in accepting a PR if it is warranted?

Thanks for reporting in 💥

I am not sure if this is because that package is not confirming to the subscription API, or because the publication-collector is relying on features that are not present in all publications.

I think it's the former; I've had some PRs adding support for various 3rd party publication packages which adds/extends the Meteor publication.

Like; it seems the Counter object instance you return doesn't have a stop() method, for example. It's returned in an array, so Meteor assumes the counter is a cursor.

As you can see in this package's code, observeHandles will include the results of _publishCursor, which I think isn't implemented fully on counter's side.

Does that make sense? Whatcha think, @nate-strauser ?

You are right, I changed the counter's code to return a handle with a stop method and that worked fine - I'll submit an issue against that package instead.

Thanks!