Situation:
+- 9000 users
Entity type with entity reference field of entity type "user". The reference type used is "views"
Form display with Widget Select2: autocomplete on - "contains"
Problem:
When the select2 widget is initialised on the form, we get a "Fatal error: Allowed memory size exhausted in /var/www/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1276".
This is because the select2 widget will fetch all results from the view, without pagination and thus results in a load of +- 9000 users which is a bit much.
(possible) Solution:
The Select2 widget will look for all valid referenceable Entities.
This happens in the Element/Select2.php file on line 186. There we should find something to override the default behavior because now it acts more or less like a default select element where this issue would also be the case, hence the lazy load that is needed.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | select2-views-handler-memory-exceeded-3105844-3-D8.patch | 1.26 KB | ReBa |
Comments
Comment #2
ReBa commentedComment #3
ReBa commentedI've solved it by checking if the $ids array is empty or not.
This way, the validation only occurs on the entity ids that are provided and the huge list validation is ignored.
Patch tested against 1.5 version and 1.x-dev version.
Can someone review?
Comment #4
chr.fritschI created a PR here: https://github.com/thunder/select2/pull/81
Comment #6
chr.fritschCrediting @Murz for his work on #3090091: Select2 with Entity Reference autocomplete views hangs on submit with empty results when multuple = true
Comment #8
chr.fritschCrediting @mtodor for his review
Comment #10
chr.fritschMerged
Comment #12
chucksimply commentedDoesn't look like this patch has been committed to the latest prod version - 8.1.13 yet. Still need to apply the patch manually.