Details
-
Bug
-
Resolution: Fixed
-
Medium
-
4.3.0
-
None
Description
Hi,
I had to important a lot of content in eZ publish and got a problems with my script : the first object were inserted quite fast, but afetr few thousands, the script become very slow.
After some profiling, I found the issue and then patch it. The function version uses array_key_exists on a cache to speedup itself. However, this function is somehow broken : with really big array, it become very slow (I assume this is because the array is passed by copy and not by reference).
Anyway, I use the isset instead. isset and array_key_exists are not 100% equivalent (isset return false when an array element is setted to null) but this doesn't matter here. isset does suffer the issue.
Here is the patch (kernel/classes/ezcontentobject.php:1141) :
function version( $version, $asObject = true ) { if ( $asObject ) { global $eZContentObjectVersionCache; if ( !isset( $eZContentObjectVersionCache ) ) // prevent PHP warning below $eZContentObjectVersionCache = array(); //Patch by Amaury SECHET for performances issues with big caches. $isCached = isset( $eZContentObjectVersionCache[$this->ID] ) && isset( $eZContentObjectVersionCache[$this->ID][$version] ); /* Original test from eZ publish. $isCached = array_key_exists( $this->ID, $eZContentObjectVersionCache ) && array_key_exists( $version, $eZContentObjectVersionCache[$this->ID] ); */ if ( $isCached ) { return $eZContentObjectVersionCache[$this->ID][$version]; } else { $eZContentObjectVersionCache[$this->ID][$version] = eZContentObjectVersion::fetchVersion( $version, $this->ID, $asObject ); return $eZContentObjectVersionCache[$this->ID][$version]; } } else { return eZContentObjectVersion::fetchVersion( $version, $this->ID, $asObject ); } }
Steps to reproduce
Just importe few thousand content with a custom PHP script using the eZ publish API.