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:
parent
b40c4a95e5
commit
a8b42b3ce3
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: performance
|
||||||
|
|
||||||
|
Don't update the script data transient for the same data
|
|
@ -41,6 +41,13 @@ class Api {
|
||||||
*/
|
*/
|
||||||
private $script_data = null;
|
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.
|
* 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 ) {
|
if ( is_null( $this->script_data ) || $this->disable_cache ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ( ! $this->script_data_modified ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
set_transient(
|
set_transient(
|
||||||
$this->script_data_transient_key,
|
$this->script_data_transient_key,
|
||||||
wp_json_encode(
|
wp_json_encode(
|
||||||
|
@ -216,6 +226,7 @@ class Api {
|
||||||
'version' => ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ),
|
'version' => ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ),
|
||||||
'dependencies' => ! empty( $asset['dependencies'] ) ? $asset['dependencies'] : [],
|
'dependencies' => ! empty( $asset['dependencies'] ) ? $asset['dependencies'] : [],
|
||||||
);
|
);
|
||||||
|
$this->script_data_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return asset details as well as the requested dependencies array.
|
// Return asset details as well as the requested dependencies array.
|
||||||
|
|
Loading…
Reference in New Issue