Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-11456

speed up file copy operation in mysql cluster file handler

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Obsolete
    • Icon: Medium Medium
    • None
    • 3.9.3
    • Legacy > Clustering
    • 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 ) )

      { eZDebug::writeError( $srcFilePath, "Failed to fetch source file data on copying." ); mysql_query( 'ROLLBACK', $this->db ); return false; }

      */

      $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

        Activity

          People

            unknown unknown
            72f8acac-185f-4a54-9470-a7473f50daab@accounts.ibexa.co Gaetano Giunta
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: