Problem/Motivation

  plugin.cache_clearer:
    class: Drupal\Core\Plugin\CachedDiscoveryClearer
    lazy: true

However the service is always instantiated and used directly so the lazy proxy is pointless:

\Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();

Even worse, the service is not lazily instantiated anyway:

> $proxy = \Drupal::service('plugin.cache_clearer');
= Drupal\Core\ProxyClass\Plugin\CachedDiscoveryClearer {#8061}

> (new ReflectionProperty($proxy, 'service'))->getValue($proxy);
= Drupal\Core\Plugin\CachedDiscoveryClearer {#8062}

The $service property should not be set until a method is called on the actual service, but the addCachedDiscovery method calls configured in PluginManagerPass trigger the instantiation of the real service as soon as the proxy service is created.

Steps to reproduce

Proposed resolution

Remove the lazy proxy. Use a tagged iterator instead of calls to addCachedDiscovery.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3432827

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

longwave created an issue. See original summary.

longwave’s picture

Issue summary: View changes

longwave’s picture

Status: Active » Needs work
longwave’s picture

Title: Use tagged iterator in plugin.cache_clearer instead of a lazy service » [PP-1] Use tagged iterator in plugin.cache_clearer instead of a lazy service
Status: Needs work » Postponed
longwave’s picture

Title: [PP-1] Use tagged iterator in plugin.cache_clearer instead of a lazy service » Use tagged iterator in plugin.cache_clearer instead of a lazy service
Status: Postponed » Needs work
longwave’s picture

Status: Needs work » Needs review
smustgrave’s picture

Any recommended way for testing this one?

longwave’s picture

It's a kinda low level refactoring, any automated test coverage that uses the plugin.cache_clearer service directly or indirectly should be enough to prove I haven't broken anything.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Ran the test-only feature https://git.drupalcode.org/issue/drupal-3432827/-/jobs/1378533 which I'll admit I'm leaning on.

Looking at the refactor though don't see anything that stands out that could be a problem. And tests are still passing.

catch’s picture

Status: Reviewed & tested by the community » Needs work

This looks good. There are constructor and interface changes here, but I really wonder why we have an interface for this at all.

Tried to think what a deprecation looks like, I think we need a 10.3.x MR that adds @deprecated to the interface method we're removing. I'm not sure we should do anything else though because this is so low level and unlikely to be interacted with. Added a CR.

longwave’s picture

Status: Needs work » Needs review

The problem is that by leaving the method on the interface, even if deprecated, is that anyone else implementing has to also leave the implementation in place. Instead I have still removed the method from the interface, but kept it on the concrete class, and added BC so it still works but issues a deprecation if you call the old method.

This is also too late for 10.3 now, so I have deprecated in 11.1 for removal in 12.0.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Failure seems unrelated to this change, HEAD may be broken as I'm seeing the same failure across multiple MRs

Deprecation update seems good though.

alexpott’s picture

@longwave why did you remove autoconfiguration?

catch’s picture

Status: Reviewed & tested by the community » Needs review
longwave’s picture

@alexpott that only works if you specify autoconfigure: true in each services.yml that declares a plugin manager, so it's not backward compatible (similar to what we found in #3446026: Adding media library openers use autoconfigure and tags in 10.3.x has BC consequences)

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Question answered, back to RTBC.

  • catch committed 2d68d830 on 11.x
    Issue #3432827 by longwave: Use tagged iterator in plugin.cache_clearer...
catch’s picture

Status: Reviewed & tested by the community » Fixed

OK yeah I tried to use autoconfigure in another MR recently and ran into the same issue that every services.yml needs to enable it. We should open an issue to do that in core and try to figure out a way to encourage contrib to do it (or could we switch things so it's enabled by default in a minor?).

Also talked to @longwave about whether we should try to backport this to 10.4.x, but since it shouldn't affect contrib at all, it doesn't really help with 10.4.x/11.1.x compatibility. So... let's leave it in 11.1.x.

Committed/pushed to 11.x, thanks!

catch’s picture

quietone’s picture

Adding tag for follow up in #19

The change record is mostly a diff. The change record should explain the change, what sites are affected and the action that needs to be taken.

smustgrave’s picture

Issue tags: -Needs followup

Opened #3449635: Enable autoconfigure for services.yml

Not sure I can update the CR

znerol’s picture

Fixed the change record. I hardly can imagine that anybody is overriding this service or calling into addCachedDiscovery() from some weird place. What do I know, though...

quietone’s picture

The followup created in in #22 was closed as a duplicate. The follow up already existed, it is #3449569: Use autoconfigure more in core

@znerol, thank you. That is much better.

The change record is published.

quietone’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.