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>&nbsp;&nbsp; // Create a subrequest to the internal API route.<br>&nbsp;&nbsp;&nbsp; $mainRequest = $this-&gt;requestStack-&gt;getCurrentRequest();<br>&nbsp;&nbsp;&nbsp; $subRequest = Request::create(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Url::fromRoute('experience_builder.api.config.list', ['xb_config_entity_type_id' =&gt; Component::ENTITY_TYPE_ID])-&gt;toString(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'GET',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $mainRequest?-&gt;cookies-&gt;all() ?? [],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $mainRequest?-&gt;server-&gt;all() ?? []<br>&nbsp;&nbsp;&nbsp; );<br>&nbsp;&nbsp;&nbsp; $subRequest-&gt;attributes-&gt;set('_format', 'json');<br><br>&nbsp;&nbsp;&nbsp; $available_components_response = $this-&gt;httpKernel-&gt;handle($subRequest, HttpKernelInterface::SUB_REQUEST);</pre><h3 id="ui-changes">User interface changes</h3>
issue