When building a view for listing content that contain a specific Taxonomy Term or the Term's children terms, the core provides a special contextual filter: "Has taxonomy term ID (with depth)". As the Taxonomy Vocabulary grows over time, that contextual filter causes slowdowns on those view pages. We experienced a few seconds long server response time for these views when we had more than 100 000 terms and nodes. Also, because of that we started to have really bad scores in PageSpeed Insights. So unless you're in the same boat, you probably don't need this extra module, yet.
We developed this module to replace the slow contextual filter with a faster solution: by indexing all parent Term IDs in a separate taxonomy_parents_index table (along with the Term's own ID).
One drawback of this solution is that it needs to maintain the records in the separate database table every time a Taxonomy Term is created, updated or deleted.
Of course, an alternative solution would be using Search API, indexing the nodes and the term hierarchy, and replacing the default taxonomy term views with ones that list content from the Search API index with the term field as the contextual filter. But that can make it challenging when you have more than 1 term reference field (for example Tag + Category) and you'd like to have a general view listing that works for both Tags and Categories, just like the view listing in Drupal by default without Search API. This module solves this whole thing without depending on Search API and you can continue using the default taxonomy term views in your site.
Usage
- Make sure to have a few Taxonomy Terms.
- Go to /admin/taxonomy_term_parents_reindex and click to 'Reindex' to index the parents in the custom table.
To replace the "Has taxonomy term ID (with depth)" contextual filter in the Taxonomy term (Content) View, you need to:
- Remove it
- Add a relationship called "Join from taxonomy_index to taxonomy_parents_index"
- Tick the checkbox at "Require this relationship" and click to Apply
- Add the "Parent ID" contextual filter (it under Category "Taxonomy Parents Index") and click to Apply
- At the contextual filter settings under "WHEN THE FILTER VALUE IS NOT IN THE URL" click to "Provide default value" and set it to "Taxonomy term ID from URL".
- Under "When the filter value IS in the URL or a default is provided" check Override title and set
{{ arguments.ptid }} - Click to Apply.
- In the view's header settings click to "Global: Rendered entity - Taxonomy term (Global: Rendered entity - Taxonomy term)".
- Set the "Taxonomy term ID" to
{{ raw_arguments.ptid }}and click to Apply - Save the view.
Project information
Seeking new maintainer
The current maintainers are looking for new people to take ownership.Maintenance fixes only
Considered feature-complete by its maintainers.- Project categories: Performance, Site structure
34 sites report using this module
- Created by kaszarobert on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.