Problem/Motivation

Any Edit form for an entity that has a lot of usages start to load slower, even causing the WSOD with 500 HTTP code.
Profiler log:
profile

Steps to reproduce

1. Remove the listSources call
Remove the listSources call entirely from entity_usage_form_alter:

<?php
  $usage_data = \Drupal::service('entity_usage.usage')->listSources($entity);
  if (empty($usage_data)) {
    return;
  }
?>

Reasoning:
It makes little sense to load thousands of entities simply to conditionally display a warning message.
Given that this warning does not block editing or saving, it is impractical to force a wait time of 10–100+ seconds just to decide whether to show a message.
Additionally, the $usage_data variable is not utilized in the error message text or anywhere else in the function.

2. Updated Message Wording
a. Edit Warning:
Current: Modifications on this form will affect all existing usages of this entity.
Suggested: Modifications made here may affect all existing usages of this entity.
b. Deletion/Recorded Usages:
Current: There are recorded usages of this entity.
Suggested: There may be recorded usages of this entity. Please verify usage before proceeding with deletion.

Remaining tasks

User interface changes

API changes

Data model changes

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

dmitry.korhov created an issue. See original summary.

dmitry.korhov’s picture

Status: Active » Needs review

alexpott made their first commit to this issue’s fork.

alexpott’s picture

@dmitry.korhov this is a nice find and can be improved - however I think can keep the current messages and functionality.

I've pushed an alternate fix that limits the query to 1 row which will be quick.

  • alexpott committed 710595f5 on 5.x
    fix: #3583694 Performance issues on Edit Entity form with a lot of...

  • alexpott committed 17927df3 on 8.x-2.x
    fix: #3583694 Performance issues on Edit Entity form with a lot of...
alexpott’s picture

Version: 5.x-dev » 8.x-2.x-dev
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

dmitry.korhov’s picture

@alexpott,
limit makes sense, especially having listSources supports limit already.
Thank you for fix!