Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHPORM-56 Replace Collection proxy class with Driver monitoring #3137

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

Merged
GromNaN merged 2 commits into mongodb:5.0 from GromNaN:PHPORM-56
Sep 6, 2024

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 5, 2024
edited
Loading

Fix PHPORM-56

Use MongoDB driver monitoring feature to log all commands.

Benefit: any 3rd party class that accepts a MongoDB\Collection instance can be used and still having query logs in Laravel.

Upgrade guide:

  • Change type hints from MongoDB\Laravel\Collection to MongoDB\Collection.
- use MongoDB\Laravel\Collection;
+ use MongoDB\Collection;

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file

@GromNaN GromNaN force-pushed the PHPORM-56 branch 3 times, most recently from 6db1052 to 0f2f584 Compare September 5, 2024 16:04
@GromNaN GromNaN marked this pull request as ready for review September 5, 2024 16:05
@GromNaN GromNaN requested review from a team as code owners September 5, 2024 16:05
@GromNaN GromNaN force-pushed the PHPORM-56 branch 2 times, most recently from a187abc to 2b02660 Compare September 5, 2024 16:13
"illuminate/events": "^11",
"illuminate/support": "^11",
"mongodb/mongodb": "^1.15"
"mongodb/mongodb": "^1.18"
Copy link
Member Author

@GromNaN GromNaN Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GromNaN GromNaN requested review from jmikola and removed request for alcaeus September 5, 2024 16:18
@GromNaN GromNaN added this to the 5.0 milestone Sep 6, 2024
* Remove `MongoFailedJobProvider`, replaced by Laravel `DatabaseFailedJobProvider` by @GromNaN in [#3122](https://github.com/mongodb/laravel-mongodb/pull/3122)
* Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124)
* Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132)
* Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137)
Copy link
Member

@alcaeus alcaeus Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might apply to other BC breaks as well, but do we want to leverage deprecations in 1.x to announce the break?

Copy link
Member Author

@GromNaN GromNaN Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can mark the class as deprecated in 1.x. Unless we add an option to switch the monitoring feature from the proxy class to the monitoring events, there will be no way to disable the deprecation.

Copy link
Member

@alcaeus alcaeus Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it - not sure we need to do this, just wanted to check 👍


$command = [];
foreach (get_object_vars($startedEvent->getCommand()) as $key => $value) {
if ($key[0] !== '$' && ! in_array($key, ['lsid', 'txnNumber'])) {
Copy link
Member

@alcaeus alcaeus Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never checked the performance of this, but why not use str_starts_with?

Copy link
Member Author

@GromNaN GromNaN Sep 6, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array key is never empty, and I need to check only 1 char. This skips 1 method call.

public function benchStrStartsWith()
{
 $key = '$db';
 return str_starts_with($key, '$');
}
public function benchStrictCmp()
{
 $key = '$db';
 return $key[0] === '$';
}
benchStrStartsWith......................I2 - Mo0.185μs (±0.26%)
benchStrictCmp..........................I2 - Mo0.135μs (±0.60%)

alcaeus and jmikola reacted with thumbs up emoji
Co-authored-by: Andreas Braun <git@alcaeus.org>
@GromNaN GromNaN removed the request for review from jmikola September 6, 2024 09:37
@GromNaN GromNaN merged commit 74f219c into mongodb:5.0 Sep 6, 2024
@GromNaN GromNaN deleted the PHPORM-56 branch September 6, 2024 12:35
public function disconnect()
{
$this->connection?->removeSubscriber($this->commandSubscriber);
$this->commandSubscriber = null;
Copy link
Member

@jmikola jmikola Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unregistering the subscriber seems correct, but I'm more generally curious how the disconnect() method is used in Laravel. Wouldn't it be misleading to users given that PHPC persists the connections by default?

I assume Laravel never uses the disableClientPersistence driver option.

Copy link
Member Author

@GromNaN GromNaN Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just making sure that the objects are deleted without requiring a garbage collector cycle.

Copy link
Member

@jmikola jmikola Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you made the additions to this method. It was a more general question about what the purpose of disconnect() was for the Laravel MongoDB library. Is it something we're obligated to implement for Eloquent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jmikola jmikola jmikola left review comments

@alcaeus alcaeus alcaeus approved these changes

@norareidy norareidy norareidy approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

5.0

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /