Use subrequests when getting component list in `::getAllComponentsKeyedBySource()`
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3545477. -->
Reported by: [mglaman](https://www.drupal.org/user/2416470)
Related to !63
>>>
<h3 id="overview">Overview</h3>
<p>XbAiPageBuilderHelper::getAllComponentsKeyedBySource calls ApiConfigControllers::list multiple times and is expensive, calls controller directly. Performing a subrequest would probably improve speed by hitting dynamic page cache.</p>
<p>It took 1.28s with a prompt that called it 5x times, so 76s. 15s per call.</p>
<p><img src="https://www.drupal.org/files/issues/2025-09-08/Screenshot%202025-09-08%20at%2010.29.00%E2%80%AFAM.png"></p>
<p>Subrequest for caching component list to improve performance. Brought getComponentContextForAi down to 62ms for 2 calls.</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<pre> // Create a subrequest to the internal API route.<br> $mainRequest = $this->requestStack->getCurrentRequest();<br> $subRequest = Request::create(<br> Url::fromRoute('experience_builder.api.config.list', ['xb_config_entity_type_id' => Component::ENTITY_TYPE_ID])->toString(),<br> 'GET',<br> [],<br> $mainRequest?->cookies->all() ?? [],<br> [],<br> $mainRequest?->server->all() ?? []<br> );<br> $subRequest->attributes->set('_format', 'json');<br><br> $available_components_response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);</pre><h3 id="ui-changes">User interface changes</h3>
issue