Skip to content

Commit

Permalink
Search for asset in two passes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lettertwo committed Dec 13, 2022
1 parent 67b7a8f commit 518a398
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/dev/query/src/cli.js
Expand Up @@ -155,16 +155,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;
Expand Down

0 comments on commit 518a398

Please sign in to comment.