ENHANCEMENT: Improved performance of DataObject::hasField()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84165 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-08-11 08:57:14 +00:00
parent 38349122d6
commit a74129b5a6

View File

@ -2096,7 +2096,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
return ( return (
array_key_exists($field, $this->record) array_key_exists($field, $this->record)
|| $this->hasDatabaseField($field) || $this->hasDatabaseField($field)
|| array_key_exists($field, $this->db())
|| $this->hasMethod("get{$field}") || $this->hasMethod("get{$field}")
); );
} }
@ -2110,13 +2109,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
*/ */
public function hasDatabaseField($field) { public function hasDatabaseField($field) {
// Add base fields which are not defined in static $db // Add base fields which are not defined in static $db
$fixedFields = array( static $fixedFields = array(
'ID' => 'Int', 'ID' => 'Int',
'ClassName' => 'Enum', 'ClassName' => 'Enum',
'LastEdited' => 'SSDatetime', 'LastEdited' => 'SSDatetime',
'Created' => 'SSDatetime', 'Created' => 'SSDatetime',
// Add fields from Versioned decorator
'Version' => $this->hasExtension('Versioned') ? 'Int' : false,
); );
if(isset($fixedFields[$field])) return true; if(isset($fixedFields[$field])) return true;
@ -2130,8 +2127,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* *
* @param string $field Name of the field * @param string $field Name of the field
* @return string The field type of the given field * @return string The field type of the given field
*/ */ public function hasOwnTableDatabaseField($field) {
public function hasOwnTableDatabaseField($field) {
// Add base fields which are not defined in static $db // Add base fields which are not defined in static $db
if($field == "ID") return "Int"; if($field == "ID") return "Int";
if($field == "ClassName" && get_parent_class($this) == "DataObject") return "Enum"; if($field == "ClassName" && get_parent_class($this) == "DataObject") return "Enum";