From 24089496dbf2731a0cc9fba7b93d5db84fb98643 Mon Sep 17 00:00:00 2001 From: Eric Eldredge Date: Thu, 8 Sep 2022 19:38:50 -0400 Subject: [PATCH] Search for asset in two passes First pass optimistically looks for a matching id. Second pass will examine asset symbols, which could be much slower if there are a lot of assets and symbols. --- packages/dev/query/src/cli.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/dev/query/src/cli.js b/packages/dev/query/src/cli.js index 9d51741c17c..a6caf8a0012 100644 --- a/packages/dev/query/src/cli.js +++ b/packages/dev/query/src/cli.js @@ -165,16 +165,20 @@ function findAssetWithSymbol(local: string) { ); let asset; - outer: for (let node of assetGraph.nodes.values()) { - if (node.type === 'asset') { - // Search against the id used by the JSTransformer and ScopeHoistingPackager, - // not the final asset id, as it may have changed with further transformation. - if (node.value.meta.id === assetId) { - asset = node; - break; - } else if (node.value.symbols) { - // If the asset couldn't be found by searching for the id, - // search for the local name in asset used symbols. + // Search against the id used by the JSTransformer and ScopeHoistingPackager, + // not the final asset id, as it may have changed with further transformation. + for (let node of assetGraph.nodes.values()) { + if (node.type === 'asset' && node.value.meta.id === assetId) { + asset = node; + break; + } + } + + // If the asset couldn't be found by searching for the id, + // search for the local name in asset used symbols. + if (asset == null) { + outer: for (let node of assetGraph.nodes.values()) { + if (node.type === 'asset' && node.value.symbols) { for (let symbol of node.value.symbols.values()) { if (symbol.local === local) { asset = node;