Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

Migrate for Meteor 3.0 #306

Open jankapunkt opened 9 months ago

jankapunkt commented 9 months ago

Continuing from #309

jankapunkt commented 4 months ago

Once CI runs we should release a beta asap, wdyt @StorytellerCZ

StorytellerCZ commented 4 months ago

Merged in from #309 as I couldn't push to the original branch for some reason. There are several breaking changes.

StorytellerCZ commented 3 months ago

@bhunjadi I will be watching your fork if anything comes up. I will release a beta shortly, but given that the tests and lint fail we have to look into that @jankapunkt

StorytellerCZ commented 3 months ago

Lint is working and green again!

StorytellerCZ commented 3 months ago

Published matb33:collection-hooks@2.0.0-beta.2

@jankapunkt run into the Meteor version mismatch issue that you were complaining in the past. I think that might also be what is screwing the tests locally.

StorytellerCZ commented 3 months ago

So I managed to get the tests running with the release flag locally. Still have a lot of them stuck and one error. @jankapunkt I think we need to add script for running the test in GitHub Actions properly. I don't remember now which package would be best for that. While at it we should probably standardize this for all the packages that use TinyTests.

harryadel commented 3 months ago

Now the test suit is running properly, at first it wasn't running due to a missing dependency (jquery) and later on it was getting stuck as an async test was still waiting but nothing was being returned.

cc @StorytellerCZ @jankapunkt @bhunjadi

StorytellerCZ commented 3 months ago

@harryadel perfect! Now we'll merge @bhunjadi latest improvements and then fix remaining tests. We can then release an RC and the last thing remaining will be documentation and migration guide.

StorytellerCZ commented 3 months ago

@bhunjadi changes merged, so now we need to fix any broken tests. Either way I will try to release a new beta today.

harryadel commented 3 months ago

cc @StorytellerCZ @bhunjadi

There was a failing test I had to fix. The tests checks for the removal of documents by counting the number of documents, and something causes multiple entries yet the removed document is gone so the test got reworked to just check for that.

I'm going to attempt a new release if I've the rights, if not then it's on you @StorytellerCZ to have a new release today!

StorytellerCZ commented 3 months ago

Will do!

StorytellerCZ commented 3 months ago

Thanks to @jankapunkt for doing the release!

brianlukoff commented 3 months ago

I'm getting this error from montiapm:agent on startup with the RC (wasn't getting the error with the previous beta):

TypeError: Cannot read properties of undefined (reading 'prototype')
    at hijackNextObject (packages/montiapm:agent/lib/hijack/db/hijack-next-object.js:6:42)
    at hijackDBOps (packages/montiapm:agent/lib/hijack/db/index.js:46:3)
    at packages/montiapm:agent/lib/hijack/instrument.js:53:5
    at initAsync (packages/montiapm:meteorx/src/server.js:40:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at /tools/static-assets/server/boot.js:453:5
    at /tools/static-assets/server/boot.js:504:7
    at startServerProcess (/tools/static-assets/server/boot.js:501:3)
jankapunkt commented 3 months ago

The question is now, whether this is to be fixed here or in montiapm:agent @StorytellerCZ @harryadel @zodern

StorytellerCZ commented 2 months ago

I think if everyone is happy with the current state we can go for a final release. Thoughts @jankapunkt @harryadel @brianlukoff ?

brianlukoff commented 2 months ago

Unfortunately I am still getting the Monti APM error above running the RC; the beta 2 release works fine.

harryadel commented 2 months ago

@StorytellerCZ I'd rather that we hold out a bit, not only because of the Monti issue but the latest version was causing errors at our application and downgrading was the only fix. So, we need to wait a bit until more people give this a spin.

StorytellerCZ commented 2 months ago

@harryadel yes, we need to fix the tests as well. I will release another RC with the Meteor 3 final release in versions from.

StorytellerCZ commented 2 months ago

@jankapunkt 2.14 tests are failing. Not a bit issue, but it would be good to have a backward compatibility or figure out why. For myself it is not a release blocker as 3.0 tests pass. So the only real thing that we need to figure out is the MontiAPM issue that @harryadel and @brianlukoff spoke of.

Sergeant61 commented 1 month ago

Hello, what is the latest situation, when I try this version 2.16, callbacks are not triggered.

my code:


if (Meteor.isServer) {
  Messages.before.insert(async function (userId, doc) {
    doc.search = doc.search || {}

    if (doc.userId) {
      const user = await Meteor.users.findOneAsync({ _id: doc.userId }, { fields: UserSearchFieldSelector })
      doc.search.user = user
    }

    if (doc.lastAgentUserId) {
      const lastAgentUser = await Meteor.users.findOneAsync({ _id: doc.lastAgentUserId }, { fields: UserSearchFieldSelector })
      doc.search.lastAgentUser = lastAgentUser
    }

    return true
  })
}
StorytellerCZ commented 1 month ago

The tests are failing due to error in the email package which has nothing to do with this project. We might need to wait for Meteor 3.0.3 release before we are able to run tests properly.

matheusccastroo commented 4 weeks ago

For anyone also facing the montiapm related issue: the problem is that this package is trying to monkey patch the find method to support the hooks, and when doing that, it re-creates the mongo cursor and as such the montiapm:agent can't add it's metrics stuff (because it ends up without the synchronousCursor property).

I just released a version for this package (collection-hooks) without the find hooks, so if you don't use it, it will work for you: https://atmospherejs.com/quave/collection-hooks.

jankapunkt commented 4 weeks ago

Thank you @matheusccastroo for the hotfix

I think under this circumstance we should make it globally configurable which methods to hook by default. @StorytellerCZ wdyt?

StorytellerCZ commented 3 weeks ago

I don't know. The issue is with the insert hook which configuration would not really resolve. I'm fine with optimization of hooking only collections which actually have hooks assigned.

zodern commented 3 weeks ago

The issue with montiapm:agent is more an issue with MeteorX - it's unable to get the synchronous cursor since the cursor it has access to is different than the one the fetch is run on when using collection hooks:

https://github.com/monti-apm/meteorx/blob/bd14ff6df893d18854367a1689e0c0e20e7b8b81/src/mongo-livedata.js#L64-L70

https://github.com/Meteor-Community-Packages/meteor-collection-hooks/blob/8484d71158d9ea48651c54d2c0eb5e4016ad55b4/find.js#L58-L64

I'm not familiar with this package, but a couple ideas are:

harryadel commented 2 weeks ago

Guys, I released a new version matb33:collection-hooks@2.0.0-rc.4. Please give it a test run. I tried it in my local application but something is not quite right so I'm still looking into it.

StorytellerCZ commented 2 weeks ago

So pretty sure now that the latest rc caused my website to fall into infinite loading. Not sure why, but reverting to rc.4 fixed the issue.