Avoid loading all terms on the taxonomy overview form

Created on 28 January 2014, almost 11 years ago
Updated 20 January 2024, 10 months ago

Problem/Motivation

When a taxonomy vocabulary contains too many terms, it is absolutely impossible to reach some pages like taxonomy overview, even if their content is paginated, because of huge memory usage.

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/web/core/lib/Drupal/Core/Cache/DatabaseBackend.php on line 167

This is caused by the taxonomy_get_tree function for huge taxonomies, but for medium sized taxonomies, this is also caused by the fact that we never clean unused variables.

For information, with a 72000 terms taxonomy (what is not so many for big websites) :

$start = memory_get_usage(TRUE);
$tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vid); // 72000 terms
$used_memory = memory_get_usage(TRUE) - $start;
echo $used_memory; // ~ 242 MB

Proposed resolution

Unset loadTree result when it is not needed anymore. This will not save the life of huge websites, but this will definetely help medium ones to stay usables.

Refactor the implementation to use less memory in general and especially with pagination.

Remaining tasks

Post the patch

User interface changes

None

API changes

None

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
TaxonomyΒ  β†’

Last updated 5 days ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @xjm
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡«πŸ‡·France duaelfr Montpellier, France

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024