Ensure to cache just the form IDs

Created on 9 March 2017, over 7 years ago
Updated 18 March 2023, over 1 year ago

Problem/Motivation

The cache->set() call currently stores the entire API result from hubspot forms.

This has a couple of disadantages:

  • We actually just need the form_ids, so we always calculate them, and just cache the entire form object
  • Depending on the system the form objects might be HUGE and as such cause cache errors:Warning: Error while sending QUERY packet. PID=92286 in Drupal\Core\Database\Statement->execute() (line 59 of /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Database/Statement.php) #0 /Users/dawehner/www/d8ixiacom/docroot/core/includes/bootstrap.inc(548): _drupal_error_handler_real(2, 'Error while sen...', '/Users/dawehner...', 59, Array) #1 [internal function]: _drupal_error_handler(2, 'Error while sen...', '/Users/dawehner...', 59, Array) #2 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Database/Statement.php(59): PDOStatement->execute(Array) #3 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Database/Connection.php(610): Drupal\Core\Database\Statement->execute(Array, Array) #4 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(81): Drupal\Core\Database\Connection->query('SELECT 1 FROM {...', Array, Array) #5 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(199): Drupal\Core\Database\Driver\mysql\Connection->query('SELECT 1 FROM {...', Array, Array) #6 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php(576): Drupal\Core\Database\Driver\mysql\Connection->queryRange('SELECT 1 FROM {...', 0, 1) #7 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Cache/DatabaseBackend.php(359): Drupal\Core\Database\Driver\mysql\Schema->tableExists('cache_default') #8 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Cache/DatabaseBackend.php(168): Drupal\Core\Cache\DatabaseBackend->ensureBinExists() #9 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Cache/DatabaseBackend.php(152): Drupal\Core\Cache\DatabaseBackend->setMultiple(Array) #10 /Users/dawehner/www/d8ixiacom/docroot/modules/contrib/hubspot_forms/src/HubspotFormsCore.php(33): Drupal\Core\Cache\DatabaseBackend->set('hubspot_forms', Array) #11 /Users/dawehner/www/d8ixiacom/docroot/modules/contrib/hubspot_forms/src/Plugin/Field/FieldWidget/HubspotFormSelectWidget.php(38): Drupal\hubspot_forms\HubspotFormsCore->getFormIds() #12 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(324): Drupal\hubspot_forms\Plugin\Field\FieldWidget\HubspotFormSelectWidget->formElement(Object(Drupal\Core\Field\FieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState)) #13 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(189): Drupal\Core\Field\WidgetBase->formSingleElement(Object(Drupal\Core\Field\FieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState)) #14 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(104): Drupal\Core\Field\WidgetBase->formMultipleElements(Object(Drupal\Core\Field\FieldItemList), Array, Object(Drupal\Core\Form\FormState)) #15 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(168): Drupal\Core\Field\WidgetBase->form(Object(Drupal\Core\Field\FieldItemList), Array, Object(Drupal\Core\Form\FormState)) #16 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Entity/ContentEntityForm.php(54): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object(Drupal\node\Entity\Node), Array, Object(Drupal\Core\Form\FormState)) #17 /Users/dawehner/www/d8ixiacom/docroot/core/modules/node/src/NodeForm.php(118): Drupal\Core\Entity\ContentEntityForm->form(Array, Object(Drupal\Core\Form\FormState)) #18 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Entity/EntityForm.php(115): Drupal\node\NodeForm->form(Array, Object(Drupal\Core\Form\FormState)) #19 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #20 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(514): call_user_func_array(Array, Array) #21 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(271): Drupal\Core\Form\FormBuilder->retrieveForm('node_product_fo...', Object(Drupal\Core\Form\FormState)) #22 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm('node_product_fo...', Object(Drupal\Core\Form\FormState)) #23 /Users/dawehner/www/d8ixiacom/docroot/core/modules/node/src/Controller/NodeController.php(113): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\node\Entity\Node)) #24 [internal function]: Drupal\node\Controller\NodeController->add(Object(Drupal\node\Entity\NodeType)) #25 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #26 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #27 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #28 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #29 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #30 /Users/dawehner/www/d8ixiacom/docroot/vendor/symfony/http-kernel/HttpKernel.php(139): call_user_func_array(Object(Closure), Array) #31 /Users/dawehner/www/d8ixiacom/docroot/vendor/symfony/http-kernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #32 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #33 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #34 /Users/dawehner/www/d8ixiacom/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #35 /Users/dawehner/www/d8ixiacom/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #36 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #37 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #38 /Users/dawehner/www/d8ixiacom/docroot/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #39 /Users/dawehner/www/d8ixiacom/docroot/core/lib/Drupal/Core/DrupalKernel.php(652): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #40 /Users/dawehner/www/d8ixiacom/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #41 {main}.

Proposed resolution

Cache just the form IDs. This solves the problem for me.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: outdated

Version

1.3

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany dawehner

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.

Production build 0.69.0 2024