Optimize memory usage for large vocabularies by replacing loadTree() with count queries in TaxonomyManagerTree and TaxonomyManagerHelper

Created on 25 July 2025, 14 days ago

Problem/Motivation

The Taxonomy Manager module uses loadTree() in getChildCount() and vocabularyIsEmpty() methods, which load entire term objects into memory to count them. This causes PHP memory limit errors with large vocabularies (over 200K terms). Performance is significantly impacted even on smaller vocabularies.

Steps to reproduce

Create a vocabulary with 200,000+ terms. Use the Taxonomy Manager interface to view or manage the vocabulary. Observe PHP memory limit errors and poor performance.

Proposed resolution

Replace loadTree() calls with efficient entity count queries using ->condition()->count(). Use ->accessCheck(FALSE) and ->range(0, 1) for optimal performance. Add error handling for robustness.

Remaining tasks

Review the patch for code standards compliance. Test with various vocabulary sizes and multilingual functionality. Confirm no regressions in existing functionality.

User interface changes

None. This is a performance optimization that maintains identical behavior.

API changes

None. Public API remains unchanged with the same method signatures and return values.

Data model changes

None. No database schema or data structure changes required.

✨ Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine tibezh

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024