Issue Bug Closed

#63669High memory consumption in DatabaseConnection->getDateTimeFormats while bulk inserting

Stephan Großberndt 12/08/14, 15:05 updated 10/02/18, 11:48

Description

Multiple calls from

  • sysext/backend/Classes/Form/DataPreprocessor.php
  • sysext/backend/Classes/Utility/BackendUtility.php
  • sysext/core/Classes/DataHandling/DataHandler.php
do
$dateTimeFormats = $GLOBALS['TYPO3_DB']->getDateTimeFormats($table);

Currently there is no table handling implemented, but for EACH CALL of every field of every record to insert a new array is generated:

    public function getDateTimeFormats($table) {
        return array(
            'date' => array(
                'empty' => '0000-00-00',
                'format' => 'Y-m-d'
            ),
            'datetime' => array(
                'empty' => '0000-00-00 00:00:00',
                'format' => 'Y-m-d H:i:s'
            )
        );
    }

Instead of creating this array multiple times it should be created as a property of the class:

    /**
     * the date and time formats compatible with the database in general
     * 
     * @var array
     */
    protected $dateTimeFormats = array(
        'date' => array(
            'empty' => '0000-00-00',
            'format' => 'Y-m-d'
        ),
        'datetime' => array(
            'empty' => '0000-00-00 00:00:00',
            'format' => 'Y-m-d H:i:s'
        )
    );

    public function getDateTimeFormats($table) {
        return $this->dateTimeFormats;
    }

For bulk insert of 6500 records:

  • memory usage of getDateTimeFormats() down from 79MB to 2kB

Reviews 2