Details
-
Improvement
-
Resolution: Obsolete
-
Medium
-
None
-
3.9.3
-
None
Description
The db handler does fetch all the blob data out of the database just to reinsert it immediately afterwards in function _copy. An INSERT ... SELECT would yeld much faster results:
function _copy( $srcFilePath, $dstFilePath )
{
// fetch source file metadata
$metaData = $this->_fetchMetadata( $srcFilePath );
if ( !$metaData ) // if source file does not exist then do nothing.
return false;
mysql_query( 'BEGIN', $this->db );
// no need to do an extra select here, just go and delete anyway. DB will take care
//if ( $this->_exists( $dstFilePath ) )
$this->_delete( $dstFilePath, true );
$srcFilePath = mysql_real_escape_string( $srcFilePath );
$dstFilePath = mysql_real_escape_string( $dstFilePath );
$datatype = $metaData['datatype'];
$filePathEscaped = $dstFilePath;
$filePathHash = md5( $filePathEscaped );
$scope = $metaData['scope'];
$contentLength = $metaData['size'];
$fileMTime = $metaData['mtime'];
// Copy file metadata.
$sql = "INSERT INTO " . TABLE_METADATA . " (datatype, name, name_hash, scope, size, mtime) VALUES";
$sql .= "('$datatype', '$filePathEscaped', '$filePathHash', '$scope', $contentLength, '$fileMTime')";
if ( !$res = mysql_query( $sql, $this->db ) )
{ eZDebug::writeError( $srcFilPath, "Failed to insert file metadata on copying." ); mysql_query( 'ROLLBACK', $this->db ); return false; }// Copy file data.
/*$srcFileID = $metaData['id'];
$sql = "SELECT filedata FROM " . TABLE_DATA . " WHERE masterid=$srcFileID";
if ( !$res = mysql_query( $sql, $this->db ) )
*/
$dstFileID = mysql_insert_id( $this->db );
//while ( $row = mysql_fetch_row( $res ) )
//{
// make the data mysql insert safe.
//$binarydata = mysql_real_escape_string( $row[0] );
$sql = "INSERT INTO " . TABLE_DATA . " (masterid, filedata) (SELECT $dstFileID, filedata FROM " . TABLE_DATA . " WHERE masterid=$srcFileID)";
if ( !mysql_query( $sql, $this->db ) || ! mysql_affected_rows($this->db))
{ eZDebug::writeError( "Failed to insert data row while copying file." ); mysql_query( 'ROLLBACK', $this->db ); mysql_free_result( $res ); return false; }//}
mysql_free_result( $res );
mysql_query( 'COMMIT', $this->db );
return true;
}
(from 3.9.3 code)
Attachments
Issue Links
- relates to
-
EZP-13872 eZ Publish (cluster) scalability effort
- Closed