Extbase: Performance improvements
authorSebastian Kurfürst <sebastian@typo3.org>
Sat, 28 Mar 2009 11:35:59 +0000 (11:35 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Sat, 28 Mar 2009 11:35:59 +0000 (11:35 +0000)
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Classes/Persistence/Mapper/ObjectRelationalMapper.php

index 374bc82..c6c37d0 100644 (file)
@@ -63,6 +63,7 @@ class Tx_ExtBase_Persistence_Mapper_DataMap {
                // SK: strtolower(..) is the wrong conversion for the class name. See the notice in the dispatcher (tt_news ->tx_ttnews)
                $this->setTableName(strtolower($this->className));
                t3lib_div::loadTCA($this->getTableName());
+               $this->initialize();
        }
 
        public function setClassName($className) {
@@ -82,7 +83,7 @@ class Tx_ExtBase_Persistence_Mapper_DataMap {
        }
 
        // SK: Why is initialize() not called in the constructor? Without initialize(), the object cannot do anything - or am I wrong here?
-       public function initialize() {
+       protected function initialize() {
                $columns = $GLOBALS['TCA'][$this->getTableName()]['columns'];
                if (is_array($columns)) {
                        $this->addCommonColumns();
@@ -119,7 +120,7 @@ class Tx_ExtBase_Persistence_Mapper_DataMap {
                        $this->addColumn($this->getHiddenColumnName(), Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_BOOLEAN);
                }
        }
-       
+
        protected function setTypeOfValue(Tx_ExtBase_Persistence_Mapper_ColumnMap &$columnMap, $columnConfiguration) {
                $evalConfiguration = t3lib_div::trimExplode(',', $columnConfiguration['config']['eval']);
                if (in_array('date', $evalConfiguration) || in_array('datetime', $evalConfiguration)) {
@@ -365,7 +366,7 @@ class Tx_ExtBase_Persistence_Mapper_DataMap {
        public function convertFieldValueToPropertyValue($propertyName, $fieldValue) {
                $columnMap = $this->getColumnMap($propertyName);
                if ($columnMap->getTypeOfValue() === Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_DATE) {
-                       $convertedValue = new DateTime(strftime('%Y-%m-%d %H:%M', $fieldValue));
+                       $convertedValue = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $fieldValue));
                } elseif ($columnMap->getTypeOfValue() === Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_BOOLEAN) {
                        if ($fieldValue === '0') {
                                $convertedValue = FALSE;
index 1f433b2..1eb47b9 100644 (file)
@@ -47,7 +47,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         * @var array
         **/
        protected $dataMaps = array();
-       
+
        /**
         * The TYPO3 DB object
         *
@@ -64,11 +64,11 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                $GLOBALS['TSFE']->includeTCA();
                $this->database = $GLOBALS['TYPO3_DB'];
        }
-       
+
        /**
         * The build query method is invoked by the Persistence Repository.
         * Build a query for objects by multiple conditions. Either as SQL parts or query by example.
-        * 
+        *
         * The following condition array would find entities with description like the given keyword and
         * name equal to "foo".
         *
@@ -78,7 +78,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         *      'blogName' => 'Foo'
         *      )
         * </pre>
-        * 
+        *
         * Note: The SQL part uses the database columns names, the query by example syntax uses
         * the object property name (camel-cased, without underscore).
         *
@@ -94,7 +94,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $where;
        }
-       
+
        /**
         * Get a where part for conditions by a specific data map. This will
         * either replace placeholders (index based array) or use the condition
@@ -102,7 +102,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         *
         * @param Tx_ExtBase_Persistence_Mapper_DataMap $dataMap The data map
         * @param array $conditions The conditions
-        * 
+        *
         * @return string The where part
         */
        protected function buildQueryByConditions(&$dataMap, $conditions) {
@@ -118,7 +118,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                                }
                        }
                }
-               return implode(' AND ', $whereParts);           
+               return implode(' AND ', $whereParts);
        }
 
        /**
@@ -128,7 +128,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         * @param Tx_ExtBase_Persistence_Mapper_DataMap $dataMap The data map
         * @param array $propertyName The property name
         * @param array $example The example condition
-        * 
+        *
         * @return string The where part
         */
        protected function buildQueryByExample(&$dataMap, $propertyName, $example) {
@@ -146,7 +146,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $sql;
        }
-       
+
        /**
         * Replace query placeholders in a query part by the given
         * parameters.
@@ -196,7 +196,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                } else {
                        $enableFields = '';
                }
-               
+
                $res = $this->database->exec_SELECTquery(
                        '*',
                        $from,
@@ -209,7 +209,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                $fieldMap = $this->getFieldMapFromResult($res);
                $rows = $this->getRowsFromResult($res);
                $this->database->sql_free_result($res);
-                               
+
                // SK: Do we want to make it possible to ignore "enableFields"?
                // TODO language overlay; workspace overlay
                $objects = array();
@@ -220,7 +220,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $objects;
        }
-       
+
        protected function getFieldMapFromResult($res) {
                $fieldMap = array();
                if ($res !== FALSE) {
@@ -233,7 +233,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $fieldMap;
        }
-       
+
        protected function getRowsFromResult($res) {
                $rows = array();
                if ($res !== FALSE) {
@@ -242,7 +242,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $rows;
        }
-       
+
        /**
         * Get the join clause for the fetch method for a specific class. This will
         * eagerly load all has-one relations.
@@ -315,7 +315,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $objects;
        }
-       
+
        protected function getProperties(Tx_ExtBase_Persistence_Mapper_DataMap $dataMap, array &$fieldMap, array &$row) {
                $properties = array();
                foreach ($dataMap->getColumnMaps() as $columnMap) {
@@ -401,7 +401,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                                $row[$parentTableFieldName] = $parentDataMap->getTableName();
                        }
                }
-               
+
                if ($dataMap->hasPidColumn()) {
                        $row['pid'] = !empty($this->cObj->data['pages']) ? $this->cObj->data['pages'] : $GLOBALS['TSFE']->id;
                }
@@ -660,8 +660,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         * @return boolean TRUE if the property is persistable (configured in $TCA)
         */
        public function isPersistableProperty($className, $propertyName) {
-               $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap($className);
-               $dataMap->initialize();
+               $dataMap = $this->getDataMap($className);
                return $dataMap->isPersistableProperty($propertyName);
        }
 
@@ -673,7 +672,6 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
        protected function getDataMap($className) {
                if (empty($this->dataMaps[$className])) {
                        $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap($className);
-                       $dataMap->initialize();
                        $this->dataMaps[$className] = $dataMap;
                }
                return $this->dataMaps[$className];