JsComponent::getScopedDependencies() and ::getDependencyLibraries() shouldn't get auto-saves unless previewing
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3539147. -->
Reported by: [mglaman](https://www.drupal.org/user/2416470)
Related to !630 !1400
>>>
<h3 id="overview">Overview</h3>
<p><em>Introduced in <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/experience_builder/issues/3518191" title="Status: Closed (fixed)">#3518191: Build import maps for code component dependencies, attach their CSS</a></span>.</em></p>
<p>I started doing some profiling of XB for performance. Viewing an XB page took 228ms roughly. However I noticed 51x queries to key_value_expire. Which is where auto-saves live.</p>
<pre>select ... from key_value_expire where ? > :now and ? in (:keys__0) and ? = :collection</pre><p>Which I thought was weird: I was viewing the page as an anonymous user. <code>JsComponent::getScopedDependencies</code> is loading autosaves. It's pretty cheap but has a scaling problem. 17 calls was only 13ms, but someone could have 50 components. AutoSaveManager has a cache and on cache miss it hits the DB for the auto-save. If we're not editing the entity, there is no auto-save. Which means we always cache miss and hit the DB for no reason.</p>
<p>I had 198 calls to Memcached::getMulti as well.</p>
<p>The problem is that <code>$dependencyAutoSave = $this->autoSaveManager->getAutoSaveEntity($js_component_dependency);</code> is always called even if we're not in a preview. Later on in <code>shouldLoadAssetFromAutoSave</code> there is a preview check.</p>
<p>We should avoid loading auto-saves unless in preview when rendering components.</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p>In <code> renderComponent</code> we should use an empty auto-save if not in preview:</p>
<pre> public function renderComponent(array $inputs, string $componentUuid, bool $isPreview = FALSE): array {<br> $component = $this->getJavaScriptComponent();<br><br> if ($isPreview) {<br> $autoSave = $this->autoSaveManager->getAutoSaveEntity($component);<br> } else {<br> $autoSave = AutoSaveEntity::empty();<br> }</pre><p>This change brought my response time from 228ms to 106ms! My memcache calls went from 198 calls to 63 and call DB queries to key_value_expire were removed.</p>
<h3 id="ui-changes">User interface changes</h3>
issue