ContentTranslationHooks::viewsDataAlter() could multiple load config entities

Created on 14 April 2025, 28 days ago

Problem/Motivation

ContentTranslationHooks::viewsDataAlter() individually checks ContentTranslationManagerInterface::isEnabled() for each entity type.

This results in an individual entity load for each entity, which is a database hit on a cache miss.

If we instead multiple load the language.content_settings config entities, it'll be a single query.

Steps to reproduce

Proposed resolution

One way to do this would be to check the config translation support within a fibers loop, to allow entity preloading to work. But we could also load all of the entities in one go when this hook is executed because we know they'll all need to be loaded anyway.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

views.module

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

Merge Requests

Comments & Activities

  • Issue created by @catch
  • 🇬🇧United Kingdom catch

    While multiple load wouldn't hurt, the bigger problem here is at least with Umami, but probably in general, the content language settings for a bundle often don't exist. This means that hooks like ContentTranslation entity_extra_field_info or anywhere else that checks ContentTranslationManager::isEnabled() can end up repeatedly attempting to load an entity that doesn't exist - and this bypasses any kind of persistent or static caching since we don't cache the non-existence of an entity.

    There are maybe three different approaches we could take:

    1. Add a static cache to ContentTranslationManager.

    2. Add a static cache to EntityStorageBase explicitly for un-found entities, we'd need to unset from there when an entity is created with the same ID.

    3. Add an upgrade path to create config entities for all bundles that don't have them, and add code to keep them in sync, but I'm not sure we can enforce that.

    Going to add an MR for #1 to show the problem, might open an issue for #2 if I can get my head around implementing it.

Production build 0.71.5 2024