Stop loading entities when we do not need to

Created on 28 January 2025, 2 months ago

Problem/Motivation

\Drupal\entity_usage\EntityUsageTrackBase::findEntityByUrlString(), \Drupal\entity_usage\EntityUsageTrackBase::findEntityByRoutedUrl() and \Drupal\entity_usage\Plugin\EntityUsage\Track\TextFieldEmbedBase::getTargetEntities() and the entity usage track plugins that use that load entities when the don't need to.

Proposed resolution

Add new methods to extract information from a URL without loading the entity for better performance and way less queries when calculating entity usage.

Remaining tasks

User interface changes

None

API changes

TBD

Data model changes

None

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @alexpott
  • Merge request !104No unnecessary entity loading β†’ (Merged) created by alexpott
  • Pipeline finished with Failed
    2 months ago
    Total: 211s
    #408414
  • Pipeline finished with Success
    2 months ago
    Total: 206s
    #408428
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    So this works up to a point but the call to \Drupal\Core\Path\PathValidatorInterface::getUrlIfValidWithoutAccessCheck in \Drupal\entity_usage\EntityUsageTrackBase::processUrl will eventually call a param convertor that will load an entity. Thinking about how to get around that... fun.

  • Pipeline finished with Success
    2 months ago
    Total: 677s
    #409133
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    So this results in over 1000 less queries for processing 400 paragraph revisions on my large site that I'm enabling entity usage on. This approach also means we're less reliant on the entity_lru_cache module to prevent memory leaks while creating the entity usage table.

  • First commit to issue fork.
  • πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain

    @alexpott thanks for working on this one! I left a question on the MR (to which I suspect the answer, but just in case). Apart from that, this is good to go as well IMO πŸ‘

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @marcoscano thanks for the review - replied to the commment.

  • Pipeline finished with Skipped
    2 months ago
    #411378
  • πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain

    Merged! Thanks again! πŸ‘

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

Production build 0.71.5 2024