Problem/Motivation

Every content entity insert, update or deletion on the site loads all search indexes, twice:

  • ContentEntityTrackingManager::getIndexesForEntity(), which already has a @todo: This is called for every single entity insert, update or deletion on the whole site. Should maybe be cached?
  • TrackingHelper::trackReferencedEntityUpdate(), for every update or deletion.

Config entities are not statically cached, so each call loads the indexes from config again, and each new index object creates its datasource plugins again.

trackReferencedEntityUpdate() also reads the foreign entity relations map from the persistent cache, once per index for every changed entity. That is cheap for a single entity, but it adds up when one save writes many entities. One example is a node with a lot of paragraphs, where every changed paragraph gets a new revision and goes through these hooks.

Proposed resolution

Add memory caching:

  • Add TrackingHelperInterface::getIndexesForTracking(), which keeps the loaded indexes in the memory cache. Use it in
    TrackingHelper::trackReferencedEntityUpdate() and ContentEntityTrackingManager::getIndexesForEntity().
  • Also keep the foreign entity relations map in memory cache.

Issue fork search_api-3636376

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rp7 created an issue.