As per kristiaanvandeneynde's request to raise a support request related to #2796197: Group or Group Node generates some massive queries, I've spent a lot of time getting down to a repeatable situation for my issues...

I have a site with ~500 groups of one group type. I have ~6000 content items in them, all of the same content type. There are no group content type fields.

The environment:
All members of a group have the permissions to add nodes to the group.
All outsiders and anonymous visitors have permissions to view groups and view the content of groups.
Visiting a group page (pathauto alias, working just fine), shows the group and a block view listing the content in that group. Paged, 24 items to a page
There is a sidebar block showing the content of the group via a $entities = $group->getContentEntities('group_node:travel_story_update'); (though disabling this block makes no difference to the issue)

The outcome:
When a user clicks to add a new node, the form displays correctly and, upon filling and clicking submit, there is a long delay, several seconds (maybe up to 10s) before the second form in the wizard is displayed.
After clicking the second form submit, either another very long delay (>10s) or the site reports and out of memory error, even with 300MB allocated!

I'm very happy to add as much detail to this as is needed - I'm getting a bit desperate to find out what on earth is going on here now. I'm really confused by it, to be honest.

Comments

rachel_norfolk created an issue. See original summary.

rachel_norfolk’s picture

Oh - and I should mention that this issue still happens to non-admin uses that have the "Bypass group access control" permission

rachel_norfolk’s picture

StatusFileSize
new332.38 KB
new453.08 KB

Right - and more debug info:

With web profiler enabled and user set to have "Bypass group access control" permission, I placed a breakpoint inside the condition in

function gnode_node_grants(AccountInterface $account, $op) {
  // Provide the master grant for users who can bypass group access.
  if ($account->hasPermission('bypass group access')) {
    return ['gnode_bypass' => [GNODE_MASTER_GRANT_ID]];     //<-- breakpoint
  }

And, after submitting the first node wizard form, I come across the breakpoint 6 times before the page renders, giving the attached output to web profiler.

After submitting the second part of the wizard, I came across the breakpoint 10 times before the page renders, giving the attached second output to web profiler.

Now, I'm actually seeing php out of memory errors, even after increasing memory for php to 300M. That huge select query in the first web profiler would lend me to think that ALL nodes are still being checked for access somehow, giving the huge IN clause. (there are ~ 6000 nodes in groups altogether - just a few dozen in the group I am adding to)

Is there anything else I can obtain?

damienmckenna’s picture

Category: Support request » Bug report
Priority: Normal » Major
Issue tags: +Performance

Sounds like a performance issue, which is a bug and at this rate seems to be a major one.

rachel_norfolk’s picture

Is there *anything* else I can get that would help determine what's going on?

damienmckenna’s picture

I don't know the module well enough to be able to help debug the problems, sorry.

rachel_norfolk’s picture

More digging because I really want to get info to make it possible to resolve this...

So, out of memory appears to happen in

( ! ) Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 4096 bytes) in /var/www/drupalvm/web/core/lib/Drupal/Core/Cache/DatabaseBackend.php on line 138
Call Stack
#	Time	Memory	Function	Location
1	0.0062	359456	{main}( )	.../index.php:0
2	0.0628	467952	Drupal\Core\DrupalKernel->handle( ???, ???, ??? )	.../index.php:19
3	0.0742	1690952	Stack\StackedHttpKernel->handle( ???, ???, ??? )	.../DrupalKernel.php:651
4	0.0742	1690952	Drupal\Core\StackMiddleware\NegotiationMiddleware->handle( ???, ???, ??? )	.../StackedHttpKernel.php:23
5	0.0742	1690952	Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle( ???, ???, ??? )	.../NegotiationMiddleware.php:50
6	0.0742	1690952	Drupal\page_cache\StackMiddleware\PageCache->handle( ???, ???, ??? )	.../ReverseProxyMiddleware.php:47
7	0.0746	1693680	Drupal\page_cache\StackMiddleware\PageCache->pass( ???, ???, ??? )	.../PageCache.php:78
8	0.0746	1693680	Drupal\Core\StackMiddleware\KernelPreHandle->handle( ???, ???, ??? )	.../PageCache.php:99
9	0.0772	2129232	Drupal\Core\StackMiddleware\Session->handle( ???, ???, ??? )	.../KernelPreHandle.php:47
10	0.0797	2236784	Symfony\Component\HttpKernel\HttpKernel->handle( ???, ???, ??? )	.../Session.php:57
11	0.0797	2237200	Symfony\Component\HttpKernel\HttpKernel->handleRaw( ???, ??? )	.../HttpKernel.php:64
12	0.1253	6576976	call_user_func_array:{/var/www/drupalvm/vendor/symfony/http-kernel/HttpKernel.php:144} ( ???, ??? )	.../HttpKernel.php:144
13	0.1253	6577040	Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}( )	.../HttpKernel.php:144
14	0.1253	6577040	Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext( ???, ??? )	.../EarlyRenderingControllerWrapperSubscriber.php:97
15	0.1253	6579576	Drupal\Core\Render\Renderer->executeInRenderContext( ???, ??? )	.../EarlyRenderingControllerWrapperSubscriber.php:124
16	0.1253	6579968	Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}( )	.../Renderer.php:574
17	0.1253	6579968	call_user_func_array:{/var/www/drupalvm/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123} ( ???, ??? )	.../EarlyRenderingControllerWrapperSubscriber.php:123
18	0.1253	6580376	Drupal\gnode\Controller\GroupNodeWizardController->addForm( ???, ??? )	.../EarlyRenderingControllerWrapperSubscriber.php:123
19	0.1470	7536656	Drupal\Core\Entity\EntityFormBuilder->getForm( ???, ???, ??? )	.../GroupNodeWizardController.php:131
20	0.1486	7661368	Drupal\Core\Form\FormBuilder->buildForm( ???, ??? )	.../EntityFormBuilder.php:48
21	0.1488	7661912	Drupal\Core\Form\FormBuilder->retrieveForm( ???, ??? )	.../FormBuilder.php:271
22	0.1491	7665352	call_user_func_array:{/var/www/drupalvm/web/core/lib/Drupal/Core/Form/FormBuilder.php:514} ( ???, ??? )	.../FormBuilder.php:514
23	0.1491	7665760	Drupal\Core\Entity\EntityForm->buildForm( ???, ??? )	.../FormBuilder.php:514
24	0.1555	7879072	Drupal\gnode\Form\GroupNodeFormStep2->form( ???, ??? )	.../EntityForm.php:115
25	0.1555	7879072	Drupal\group\Entity\Form\GroupContentForm->form( ???, ??? )	.../GroupNodeFormStep2.php:51
26	0.1555	7879072	Drupal\Core\Entity\ContentEntityForm->form( ???, ??? )	.../GroupContentForm.php:31
27	0.1555	7879848	Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm( ???, ???, ??? )	.../ContentEntityForm.php:54
28	0.1567	7887984	Drupal\Core\Field\WidgetBase->form( ???, ???, ???, ??? )	.../EntityFormDisplay.php:168
29	0.1579	7899680	Drupal\Core\Field\WidgetBase->formSingleElement( ???, ???, ???, ???, ??? )	.../WidgetBase.php:85
30	0.1579	7900056	Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget->formElement( ???, ???, ???, ???, ??? )	.../WidgetBase.php:324
31	0.1580	7902256	Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions( ??? )	.../OptionsSelectWidget.php:34
32	0.1581	7902984	Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem->getSettableOptions( ??? )	.../OptionsWidgetBase.php:116
33	0.1598	8176128	Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->getReferenceableEntities( ???, ???, ??? )	.../EntityReferenceItem.php:557
34	0.2298	9063664	Drupal\Core\Entity\EntityStorageBase->loadMultiple( ??? )	.../DefaultSelection.php:294
35	0.2304	9624984	Drupal\Core\Entity\Sql\SqlContentEntityStorage->doLoadMultiple( ??? )	.../EntityStorageBase.php:242
36	0.2304	9625008	Drupal\Core\Entity\ContentEntityStorageBase->getFromPersistentCache( ??? )	.../SqlContentEntityStorage.php:396
37	0.2431	10476216	Drupal\Core\Cache\DatabaseBackend->getMultiple( ???, ??? )	.../ContentEntityStorageBase.php:594
38	24.6110	315616968	Drupal\Core\Cache\DatabaseBackend->prepareItem( ???, ??? )	.../DatabaseBackend.php:93
39	24.6110	315617376	unserialize ( ??? )	.../DatabaseBackend.php:138

And what it is doing there is unserialising nodes. Annoyingly, it is unserialising nodes that are NOT part of the group this node is being added to!!

$cache on one example (I had a conditional breakpoint set there when memory usage was very large (thanks jp_stacey). And that breakpoint is hit for lots and lots and lots of nodes - this being the first.

stdClass Object
(
    [cid] => values:node:9474
    [data] => O:23:"Drupal\node\Entity\Node":24:{s:10:"in_preview";N;s:9:"*values";a:22:{s:3:"vid";a:1:{s:9:"x-default";s:4:"9474";}s:8:"langcode";a:1:{s:9:"x-default";s:2:"en";}s:18:"revision_timestamp";a:1:{s:9:"x-default";s:10:"1474555249";}s:12:"revision_uid";a:1:{s:9:"x-default";s:1:"1";}s:12:"revision_log";a:1:{s:9:"x-default";N;}s:3:"nid";a:1:{s:9:"x-default";s:4:"9474";}s:4:"type";a:1:{s:9:"x-default";s:19:"travel_story_update";}s:4:"uuid";a:1:{s:9:"x-default";s:36:"2be6bea7-3c75-4e5a-8ab2-76b2f5e1713e";}s:17:"isDefaultRevision";a:1:{s:9:"x-default";s:1:"1";}s:5:"title";a:1:{s:9:"x-default";s:41:"Friday 18th Sept - Santa Fe - Albuquerque";}s:3:"uid";a:1:{s:9:"x-default";s:1:"1";}s:6:"status";a:1:{s:9:"x-default";s:1:"1";}s:7:"created";a:1:{s:9:"x-default";s:10:"1474555249";}s:7:"changed";a:1:{s:9:"x-default";s:10:"1478182346";}s:7:"promote";a:1:{s:9:"x-default";s:1:"0";}s:6:"sticky";a:1:{s:9:"x-default";s:1:"0";}s:29:"revision_translation_affected";a:1:{s:9:"x-default";s:1:"1";}s:16:"default_langcode";a:1:{s:9:"x-default";s:1:"1";}s:4:"body";a:1:{s:9:"x-default";a:1:{i:0;a:3:{s:5:"value";s:680:"The heavy rains overnight have gone further south and we take a little time to explore the historic plaza downtown.It has retained some unique buildings typical of the indigenous native population.The St Franics cathederal dates to the early 1600's and the palace is the oldest public building in the USA.

A highly recommended detour on the way to Albuquerque is to take route 14 south.This is known locally as the turquoise trail and take you through beautiful canyons on the way to Cerrillos and then to Madrid.This town may not seem famous but any biker should know it as the town where "Wild Hogs" was filmed.

We have decided to stay in uptown Albuquerque for the night.";s:7:"summary";N;s:6:"format";s:9:"rich_text";}}}s:7:"comment";a:1:{s:9:"x-default";a:1:{i:0;a:6:{s:6:"status";s:1:"2";s:3:"cid";s:1:"0";s:22:"last_comment_timestamp";s:10:"1474555249";s:17:"last_comment_name";N;s:16:"last_comment_uid";s:1:"1";s:13:"comment_count";s:1:"0";}}}s:20:"field_date_of_update";a:1:{s:9:"x-default";a:1:{i:0;a:1:{s:5:"value";s:10:"2009-09-18";}}}s:13:"field_entryid";a:1:{s:9:"x-default";a:1:{i:0;a:1:{s:5:"value";s:4:"4068";}}}}s:9:"*fields";a:0:{}s:19:"*fieldDefinitions";N;s:12:"*languages";N;s:14:"*langcodeKey";s:8:"langcode";s:21:"*defaultLangcodeKey";s:16:"default_langcode";s:17:"*activeLangcode";s:9:"x-default";s:18:"*defaultLangcode";s:2:"en";s:15:"*translations";a:1:{s:9:"x-default";a:1:{s:6:"status";i:1;}}s:24:"*translationInitialize";b:0;s:14:"*newRevision";b:0;s:20:"*isDefaultRevision";s:1:"1";s:13:"*entityKeys";a:4:{s:6:"bundle";s:19:"travel_story_update";s:2:"id";s:4:"9474";s:8:"revision";s:4:"9474";s:4:"uuid";s:36:"2be6bea7-3c75-4e5a-8ab2-76b2f5e1713e";}s:25:"*translatableEntityKeys";a:5:{s:5:"label";a:1:{s:9:"x-default";s:41:"Friday 18th Sept - Santa Fe - Albuquerque";}s:8:"langcode";a:1:{s:9:"x-default";s:2:"en";}s:6:"status";a:1:{s:9:"x-default";s:1:"1";}s:3:"uid";a:1:{s:9:"x-default";s:1:"1";}s:16:"default_langcode";a:1:{s:9:"x-default";s:1:"1";}}s:12:"*validated";b:0;s:21:"*validationRequired";b:0;s:15:"*entityTypeId";s:4:"node";s:15:"*enforceIsNew";N;s:12:"*typedData";N;s:16:"*cacheContexts";a:0:{}s:12:"*cacheTags";a:0:{}s:14:"*cacheMaxAge";i:-1;s:14:"*_serviceIds";a:0:{}}
    [created] => 1482163810.027
    [expire] => -1
    [serialized] => 1
    [tags] => Array
        (
            [0] => entity_field_info
            [1] => node_values
        )

    [checksum] => 1873
    [valid] => 1
)

That sounds interesting to me...

rachel_norfolk’s picture

rachel_norfolk’s picture

I can hardly believe that I have found what appears to have been causing the issue.

Early on in the build, I set up the group_content type for the group and, in Manage Form Display, I set the Content field to be a Select list. I really didn't think any more about this.

It seems that, even though the group content form isn't really displayed as such, especially the Content field, Drupal *does* attempt to create the list as the group_content entity is created. This leads to a load of ALL eligible content entities and, eventually, an exhaustion of php memory.

Simply changing the Content field back to the default of autocomplete has transformed the site back into a nice speedy, lean one.

So, my actual issue is "resolved" but we need to find a way of preventing others falling into this trap. A form_alter to prevent the widget being changed, perhaps?

rachel_norfolk’s picture

StatusFileSize
new650 bytes

So, it seems to me that we always need to ensure that people do not use the options_select widget on group_content forms (even if the form isn't actually used as such!!)

Here's a patch. Best way I can think of doing it. I'm off for a bit of fresh air cos this has *really* flummoxed me for days...

rachel_norfolk’s picture

Status: Active » Needs review

One day, I'll actually remember to set an issue to Needs Review first time around!

damienmckenna’s picture

Status: Needs review » Needs work

How about instead of blocking what could be a useful UI for some sites, instead provide a warning to not use the selector if there are a lot of referenceable entities? At the very least the unset() line needs its indenting fixed.

rachel_norfolk’s picture

I can live with that as a suggestion - would adding text to the option be sufficient, do you think?

rachel_norfolk’s picture

Status: Needs work » Needs review
StatusFileSize
new830 bytes
new734 bytes

How about this?

damienmckenna’s picture

StatusFileSize
new1.02 KB
new763 bytes

That's good. Here's a small tweak.

damienmckenna’s picture

One question I have - should there be a check to make sure the field the correct type, so the string definition only happens when dealing with a group field?

rachel_norfolk’s picture

The field can only be of one type as it is created by the group module. We already check it is a group-generated form.

kristiaanvandeneynde’s picture

Sorry, I'm just catching up after a long sick leave/vacation. This one had me laughing out loud:

It seems that, even though the group content form isn't really displayed as such, especially the Content field, Drupal *does* attempt to create the list as the group_content entity is created. This leads to a load of ALL eligible content entities and, eventually, an exhaustion of php memory.

Reading further through the thread now, but I thought I would share that :D

P.S.: Good catch!

rachel_norfolk’s picture

You can imagine the words that came out of my potty mouth when I worked out what was going on!!! :-D

Seems a good thing to dissuade others from doing!

P.S. Glad to have you back

kristiaanvandeneynde’s picture

Right so having read up on this, I can see the issue and yet I am not sure if it's up to us to patch this. This memory issue applies to any entity reference field on any site that has a lot of content.

So while I am impressed by the way rachel_norfolk investigated this and grateful to DamienMcKenna for pitching in, I'd argue that this is something that could be addressed in core instead.

A few possible solutions that aren't mutually exclusive:

  • Disable the 'Select list' widget as an option if there are too many referable entities, showing a text below the widget selector explaining why it has been disabled.
  • When 'Select list' is already set and the options grow too large, display a warning atop the form using it. The warning would encourage them to select a different widget.

What do you think? If we decide to not take action here, I'm still very willing to assign an issue credit to both of you for the excellent progress made here.

damienmckenna’s picture

All props are due to rachel_norfolk for digging through this.

kristiaanvandeneynde’s picture

Status: Needs review » Fixed

Respectfully, closing as "works as designed" because there isn't actually anything wrong with Group here. Marking as "Fixed", though, to reward the both of you an issue credit. (The system should allow me to reward one regardless of Fixed status IMO)

rachel_norfolk’s picture

I can live with that :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.