Reduce memory usage from \Drupal\taxonomy\TermStorageInterface::loadTree() when parent is specified

Created on 29 January 2010, over 15 years ago
Updated 25 August 2024, 9 months ago

#693362: taxonomy_form_all() is dangerous β†’ just got committed (yay!) and while thinking about #556842: taxonomy_get_tree() memory issues β†’ I remembered that even if you specify a parent, the function still loads every term in the vocabulary just to check if one of them has that term as a parent, which is just horrible.

Seems like it ought to be possible to reduce memory for sub-trees by querying a slice of the tree each time. Won't be pretty but would hopefully scale better.

Should look something like this:

If $parent !=0 add WHERE parent = :parent to the query.

Then keep going down the tree with WHERE parent IN (:parents). This means you get a query for each level of depth under the term specified (rarely likely to be more than 5-6 queries) and only ever load the terms needed to return the proper tree, instead of always loading everything.

You'd also need to keep an array of all the tids loaded so far, because the final array has to be ordered by weight and name across all the terms - so that's at least two queries and a couple of extra loops, but still ought to balance out.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
TaxonomyΒ  β†’

Last updated about 18 hours ago

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

πŸ‡¬πŸ‡§United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

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