Blocks\Assets\Api: Do not attempt to update script_data transient with the same data (#50962)

* Blocks\Assets\Api: Do not attempt to update script_data transient with the same data

* Add changelog

* Update plugins/woocommerce/src/Blocks/Assets/Api.php

Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>

* Update plugins/woocommerce/changelog/50962-dont-update-transient-with-same-data

Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>

---------

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>
This commit is contained in:
Matthew Reishus 2024-09-09 10:59:58 -05:00 committed by GitHub
parent b40c4a95e5
commit a8b42b3ce3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: performance
Don't update the script data transient for the same data

View File

@ -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.