Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Make ErroneousMessagesSelector service public again #458

Merged
merged 1 commit into from
Aug 22, 2020

Conversation

core23
Copy link
Member

@core23 core23 commented Aug 2, 2020

Subject

The service is used inside a command: https://github.com/sonata-project/SonataNotificationBundle/blob/3.x/src/Command/RestartCommand.php#L118

I am targeting this branch, because this is a patch.

Changelog

### Fixed
- Make `ErroneousMessagesSelector` service public again

@core23 core23 added the patch label Aug 2, 2020
@core23 core23 requested a review from a team August 2, 2020 20:34
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.notification.erroneous_messages_selector" class="Sonata\NotificationBundle\Selector\ErroneousMessagesSelector">
<service id="sonata.notification.erroneous_messages_selector" class="Sonata\NotificationBundle\Selector\ErroneousMessagesSelector" public="true">
Copy link
Member

Choose a reason for hiding this comment

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

If this service is not always required, I think we could declare it as an alias of the private service Sonata\NotificationBundle\Selector\ErroneousMessagesSelector in order to improve the container performance.

Copy link
Member

Choose a reason for hiding this comment

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

Take a look at this thread @phansys sonata-project/SonataAdminBundle#6210 (comment)

what do you mean by improving performance using a public alias?

Copy link
Member

Choose a reason for hiding this comment

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

Take a look at this thread @phansys sonata-project/SonataAdminBundle#6210 (comment)

No problem. My suggestion had the intention to keep the service private (its id really doesn't matter for what I was trying to achieve).

what do you mean by improving performance using a public alias?

What I mean is, based on the docs, there seems to be an implicit optimization when a private service keeps private, using a public alias to access it from DIC if required.
I'm not sure if my supposal is right or not, these are the relevant paragraphs:

Private services are special because they allow the container to optimize whether and how they are instantiated. This increases the container’s performance. It also gives you better errors: if you try to reference a non-existent service, you will get a clear error when you refresh any page, even if the problematic code would not have run on that page.

However, if a service has been marked as private, you can still alias it (see below) to access this service (via the alias).

If I'm wrong about this, please forget about my comment.

Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

It could be nice to stop using ContainerAwareCommand in this bundle :)

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.notification.erroneous_messages_selector" class="Sonata\NotificationBundle\Selector\ErroneousMessagesSelector">
<service id="sonata.notification.erroneous_messages_selector" class="Sonata\NotificationBundle\Selector\ErroneousMessagesSelector" public="true">
Copy link
Member

@VincentLanglet VincentLanglet Aug 3, 2020

Choose a reason for hiding this comment

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

What about adding a TODO: remove public in next major if not used anymore by ... ?

Copy link
Member

@jordisala1991 jordisala1991 Aug 3, 2020

Choose a reason for hiding this comment

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

I would say: NEXT_MAJOR: Remove public and make use of dependency injection instead of container

I mean, it should be a requirement for NEXT_MAJOR release

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe it's the right time to do it ?

On other bundles, we made this change on the stable branch: sonata-project/SonataAdminBundle#5579

Copy link
Member

Choose a reason for hiding this comment

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

Well, IMO it should be done, but fixing a bug is fixing a bug... If @core23 wants to invest time on it, good, if not it can be merged as is (I would suggest the next_major comment so another person can work on it)

Copy link
Member

Choose a reason for hiding this comment

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

Yes sure.
Either changing the command, either adding a NEXT_MAJOR comment to this file.

@core23
Copy link
Member Author

core23 commented Aug 3, 2020

Well, IMO it should be done, but fixing a bug is fixing a bug...

That's right, we could improve our code later, but first we should fix the bug. The service was public by default in symfony 3, so we had no issue. But when bumping to symfony 4, we did not find this issue.

Can you please approve this @VincentLanglet ?

@VincentLanglet
Copy link
Member

Well, IMO it should be done, but fixing a bug is fixing a bug...

That's right, we could improve our code later, but first we should fix the bug. The service was public by default in symfony 3, so we had no issue. But when bumping to symfony 4, we did not find this issue.

Can you please approve this @VincentLanglet ?

I am just asking for a NEXT MAJOR comment

@core23
Copy link
Member Author

core23 commented Aug 22, 2020

I created an issue as a reminder #464

@VincentLanglet
Copy link
Member

Thanks !

@VincentLanglet VincentLanglet merged commit 1e69b60 into sonata-project:3.x Aug 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants