getEntityInstanceIds()/\Drupal\simple_sitemap\Manager\EntityManager::setBundleSettings causes out of memory error with a lot of content

Created on 18 May 2022, over 2 years ago
Updated 25 September 2024, 2 months ago

Problem/Motivation

When enabling a bundle with a lot of entities (hundreds of thousands, the exact limit will depend on your configured limit), this happens:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 41943040 bytes) in core/lib/Drupal/Core/Database/StatementWrapper.php on line 169

24	0.2099	20042128	Drupal\simple_sitemap\Form\EntityBundlesForm->submitForm( )	.../FormSubmitter.php:113
25	0.2171	20045072	Drupal\simple_sitemap\Manager\EntityManager->setBundleSettings( )	.../EntityBundlesForm.php:170
26	0.5865	26158256	Drupal\simple_sitemap\Entity\EntityHelper->getEntityInstanceIds( )	.../EntityManager.php:222
27	0.5993	28543216	Drupal\Core\Entity\Query\Sql\Query->execute( )	.../EntityHelper.php:263
28	0.6001	28674712	Drupal\Core\Entity\Query\Sql\Query->result( )	.../Query.php:83
29	3.0803	128937408	Drupal\Core\Database\StatementWrapper->fetchAllKeyed( )	.../Query.php:271

Steps to reproduce

Proposed resolution

To scale, the whole process would likely need to be rewritten to do this in a batch. Additionally, it could probably be skipped at least if the bundle settings change is enabling a new bundle, because nothing existing would need to be changed?

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
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.

  • 🇷🇺Russia walkingdexter

    @berdir Thanks for the issue!

    @gbyte I think the whole code in \Drupal\simple_sitemap\Manager\EntityManager::setBundleSettings() after $bundle_settings->save(); should be removed.

    • There is no reason to delete entity overrides in case bundle indexation is disabled. User can re-enable bundle indexation and overrides will be needed again.
    • There is no reason to delete entity overrides which are identical to new bundle settings. User can change bundle settings and overrides will be needed again.

    We also have a potential performance problem with \Drupal\simple_sitemap\Manager\EntityManager::removeBundleSettings() but this is a rare case. Also this shouldn't be a problem after closing #3034070: Store entity instance settings as fields on entity .

Production build 0.71.5 2024