From cd3baf4d9999886b7b7a3add730456d56b75c373 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 31 Jul 2019 10:58:18 -0400 Subject: [PATCH] Editor: Optimize common dependencies bail-out (#16839) --- packages/editor/src/store/actions.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index 8ea2c9a408de84..36190a77b47ade 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -55,6 +55,11 @@ const lastBlockSourceDependenciesByRegistry = new WeakMap; */ function* getBlocksWithSourcedAttributes( blocks ) { const registry = yield getRegistry(); + if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) { + return blocks; + } + + const blockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry ); let workingBlocks = blocks; for ( let i = 0; i < blocks.length; i++ ) { @@ -66,11 +71,6 @@ function* getBlocksWithSourcedAttributes( blocks ) { continue; } - if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) { - continue; - } - - const blockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry ); if ( ! blockSourceDependencies.has( sources[ schema.source ] ) ) { continue; } @@ -136,13 +136,13 @@ function* resetLastBlockSourceDependencies( sourcesToUpdate = Object.values( sou } const registry = yield getRegistry(); + if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) { + lastBlockSourceDependenciesByRegistry.set( registry, new WeakMap ); + } - for ( const source of sourcesToUpdate ) { - if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) { - lastBlockSourceDependenciesByRegistry.set( registry, new WeakMap ); - } + const lastBlockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry ); - const lastBlockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry ); + for ( const source of sourcesToUpdate ) { const dependencies = yield* source.getDependencies(); lastBlockSourceDependencies.set( source, dependencies ); }