Changeset 252

Show
Ignore:
Timestamp:
06/07/07 08:15:35 (1 year ago)
Author:
bermiferrer
Message:

Performance improvements.

Preventing attribute composing on models without any attribute composing settings.

Adding the possibility of disabling name-based setters/getters like setName which will be triggered by set('name',...).
This is the default value for now, but might change in a future release as it can lead to confusion.

Added also some performance comments to config/production.php

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/development.php

    r251 r252  
    22 
    33// Define constants that are used only on a development environment 
    4 // See file available_constants.php for more info 
     4// See file boot.php for more info 
    55 
    66define('AK_ENABLE_STRICT_XHTML_VALIDATION', false); // At least until the validator is fully tested 
  • trunk/config/production.php

    r2 r252  
    22 
    33// Define constants that are used only on a production environment 
    4 // See file available_constants.php for more info 
     4// See file boot.php for more info 
    55 
     6/** 
     7 * Performance tricks for production environments. 
     8 *  
     9 * Disable callback getters/setters. If you allways use  
     10 * AkActiveRecord::get('attribute_name') and AkActiveRecord::set('attribute_name', $value) 
     11 * instead of AkActiveRecord::getAttributeName and AkActiveRecord::setAttributeName 
     12 * you might want to disable thath functionality by uncommenting the next two line. 
     13 */ 
     14// ak_define('ACTIVE_RECORD_ENABLE_CALLBACK_SETTERS', false);  
     15// ak_define('ACTIVE_RECORD_ENABLE_CALLBACK_GETTERS', false);  
     16 
     17/** 
     18 * These settings can also help on heavy load sites, but please TEST that these new defaults 
     19 * don't break you working application. 
     20 *  
     21 * DONT CHANGE ANYTHING IF YOU DON'T KNOW WHAT IT MEANS. 
     22 */ 
     23// ak_define('ACTIVE_RECORD_VALIDATE_TABLE_NAMES', false); 
     24// ak_define('ACTIVE_RECORD_SKIP_SETTING_ACTIVE_RECORD_DEFAULTS', true); 
     25// ak_define('ACTIVE_RECORD_ENABLE_PERSISTENCE', true); 
     26// ak_define('ACTIVE_RECORD_CACHE_DATABASE_SCHEMA', true); 
     27// ak_define('ACTIVE_RECORD_CACHE_DATABASE_SCHEMA_LIFE', 86400); 
    628 
    729?> 
  • trunk/config/testing.php

    r2 r252  
    22 
    33// Define constants that are used only on a testing environment 
    4 // See file available_constants.php for more info 
     4// See file boot.php for more info 
    55 
    66 
  • trunk/lib/AkActiveRecord.php

    r248 r252  
    2020require_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkAssociatedActiveRecord.php'); 
    2121 
     22// Use setColumnName if available when using set('column_name', $value); 
     23ak_define('ACTIVE_RECORD_ENABLE_CALLBACK_SETTERS', true);  
     24ak_define('ACTIVE_RECORD_ENABLE_CALLBACK_GETTERS', true);  
    2225ak_define('ACTIVE_RECORD_ENABLE_PERSISTENCE', AK_ENVIRONMENT != 'testing'); 
    2326ak_define('ACTIVE_RECORD_CACHE_DATABASE_SCHEMA', AK_ACTIVE_RECORD_ENABLE_PERSISTENCE && AK_ENVIRONMENT != 'development'); 
     27ak_define('ACTIVE_RECORD_CACHE_DATABASE_SCHEMA_LIFE', 300); 
    2428ak_define('ACTIVE_RECORD_VALIDATE_TABLE_NAMES', true); 
    2529ak_define('ACTIVE_RECORD_SKIP_SETTING_ACTIVE_RECORD_DEFAULTS', false); 
     
    15601564 
    15611565 
    1562     function setAttribute($attribute, $value, $inspect_for_callback_child_method = true, $compose_after_set = true) 
    1563     { 
     1566    function setAttribute($attribute, $value, $inspect_for_callback_child_method = AK_ACTIVE_RECORD_ENABLE_CALLBACK_SETTERS, $compose_after_set = true){ 
    15641567        static $watchdog; 
    15651568 
     
    15731576 
    15741577        if($inspect_for_callback_child_method === true && method_exists($this,'set'.AkInflector::camelize($attribute))){ 
     1578            static $watchdog; 
    15751579            $watchdog[$attribute] = @$watchdog[$attribute]+1; 
    15761580            if($watchdog[$attribute] == 5000){ 
     
    15861590            $this->{$attribute.'_before_type_cast'} = $value; 
    15871591            $this->$attribute = $value; 
    1588             if($compose_after_set && !$this->requiredForCombination($attribute)){ 
     1592            if($compose_after_set && !empty($this->_combinedAttributes) && !$this->requiredForCombination($attribute)){ 
    15891593                $combined_attributes = $this->_getCombinedAttributesWhereThisAttributeIsUsed($attribute); 
    15901594                foreach ($combined_attributes as $combined_attribute){ 
     
    16221626    } 
    16231627 
    1624     function getAttribute($attribute, $inspect_for_callback_child_method = true) 
    1625     { 
    1626         static $watchdog; 
    1627  
     1628    function getAttribute($attribute, $inspect_for_callback_child_method = AK_ACTIVE_RECORD_ENABLE_CALLBACK_GETTERS) 
     1629    { 
    16281630        if($attribute[0] == '_'){ 
    16291631            return false; 
     
    16311633 
    16321634        if($inspect_for_callback_child_method === true && method_exists($this,'get'.AkInflector::camelize($attribute))){ 
     1635            static $watchdog; 
    16331636            $watchdog[@$attribute] = @$watchdog[$attribute]+1; 
    16341637            if($watchdog[$attribute] == 66){ 
     
    16431646        if(isset($this->$attribute) || (!isset($this->$attribute) && $this->isCombinedAttribute($attribute))){ 
    16441647            if($this->hasAttribute($attribute)){ 
    1645                 if ($this->isCombinedAttribute($attribute)){ 
     1648                if (!empty($this->_combinedAttributes) && $this->isCombinedAttribute($attribute)){ 
    16461649                    $this->composeCombinedAttribute($attribute); 
    16471650                } 
     
    18501853        } 
    18511854    } 
    1852     /* 
    1853     if(!empty($this->_combinedAttributes)){ 
    1854     foreach ($this->_combinedAttributes as $attribute=>$rule){ 
    1855     $pattern = $rule[0]; 
    1856     $ary = array(); 
    1857     $ary = array(); 
    1858     for ($x=1;$x<count($rule);$x++){ 
    1859     $subattribute = $rule[$x]; 
    1860     $ary[$subattribute] = $this->getAttribute($subattribute); 
    1861     } 
    1862     $this->$attribute = method_exists(&$this, $pattern.'Compose') ? $this->{$pattern.'Compose'}($ary) : vsprintf($pattern, $ary); 
    1863     } 
    1864     } 
    1865     */ 
     1855     
    18661856    function composeCombinedAttribute($combined_attribute) 
    18671857    { 
     
    25592549        if(AK_ACTIVE_RECORD_CACHE_DATABASE_SCHEMA && AK_CACHE_HANDLER > 0){ 
    25602550            $Cache =& Ak::cache(); 
    2561             $Cache->init(300); 
     2551            $Cache->init(AK_ACTIVE_RECORD_CACHE_DATABASE_SCHEMA_LIFE); 
    25622552            $Cache->clean('AkActiveRecord'); 
    25632553        } 
     
    25682558        if(isset($_SESSION['__activeRecordColumnsSettingsCache'])){ 
    25692559            $Cache =& Ak::cache(); 
    2570             $Cache->init(300); 
     2560            $Cache->init(AK_ACTIVE_RECORD_CACHE_DATABASE_SCHEMA_LIFE); 
    25712561            $Cache->save(serialize($_SESSION['__activeRecordColumnsSettingsCache']), 'active_record_db_cache', 'AkActiveRecord'); 
    25722562        } 
     
    25772567        if(!isset($_SESSION['__activeRecordColumnsSettingsCache'])){ 
    25782568            $Cache =& Ak::cache(); 
    2579             $Cache->init(300); 
     2569            $Cache->init(AK_ACTIVE_RECORD_CACHE_DATABASE_SCHEMA_LIFE); 
    25802570            if($serialized_column_settings = $Cache->get('active_record_db_cache', 'AkActiveRecord') && !empty($serialized_column_settings)){ 
    25812571                $_SESSION['__activeRecordColumnsSettingsCache'] = @unserialize($serialized_column_settings); 
  • trunk/test/fixtures/config/config.php

    r208 r252  
    1919define('AK_SITE_URL_SUFFIX', str_replace(array(join(DIRECTORY_SEPARATOR,array_diff((array)@explode(DIRECTORY_SEPARATOR,AK_TEST_DIR), 
    2020(array)@explode('/',@$_SERVER['REQUEST_URI']))),DIRECTORY_SEPARATOR),array('','/'),AK_TEST_DIR)); 
     21 
    2122 
    2223//define('AK_SKIP_DB_CONNECTION',isset($db) && $db === false);