diff --git a/plugins/woocommerce/changelog/50962-dont-update-transient-with-same-data b/plugins/woocommerce/changelog/50962-dont-update-transient-with-same-data new file mode 100644 index 00000000000..6a83f4fd019 --- /dev/null +++ b/plugins/woocommerce/changelog/50962-dont-update-transient-with-same-data @@ -0,0 +1,4 @@ +Significance: patch +Type: performance + +Don't update the script data transient for the same data \ No newline at end of file diff --git a/plugins/woocommerce/src/Blocks/Assets/Api.php b/plugins/woocommerce/src/Blocks/Assets/Api.php index 56f3a67f55d..9b191724bdb 100644 --- a/plugins/woocommerce/src/Blocks/Assets/Api.php +++ b/plugins/woocommerce/src/Blocks/Assets/Api.php @@ -41,6 +41,13 @@ class Api { */ private $script_data = null; + /** + * Tracks whether script_data was modified during the current request. + * + * @var boolean + */ + private $script_data_modified = false; + /** * Stores the hash for the script data, made up of the site url, plugin version and package path. * @@ -171,6 +178,9 @@ class Api { if ( is_null( $this->script_data ) || $this->disable_cache ) { return; } + if ( ! $this->script_data_modified ) { + return; + } set_transient( $this->script_data_transient_key, wp_json_encode( @@ -216,6 +226,7 @@ class Api { 'version' => ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ), 'dependencies' => ! empty( $asset['dependencies'] ) ? $asset['dependencies'] : [], ); + $this->script_data_modified = true; } // Return asset details as well as the requested dependencies array.