Skip to content

Refactor active record meta data to be static field #2265

wants to merge 10 commits into from

4 participants

Yii Software LLC member

Active Record meta data has been refactored to be static field.
Note about overriding "CActiveRecord::__construct()" has been added.

Relates to #2251

Yii Software LLC member

This fix reduces memory usage a little.
Memory test:

$memoryBefore = memory_get_usage();
$models = Item::model()->findAll(); // 62 records
$memoryAfter = memory_get_usage();

Original memory usage delta 966960.
After refactor memory usage delta 964152.

@cebe cebe commented on the diff Mar 27, 2013
@@ -397,10 +397,10 @@ public static function model($className=__CLASS__)
public function getMetaData()
- if($this->_md!==null)
- return $this->_md;
- else
- return $this->_md=self::model(get_class($this))->_md;
+ $className=get_class($this);
+ if(!array_key_exists($className,self::$_md))
+ self::$_md[$className]=new CActiveRecordMetaData($this);
Yii Software LLC member
cebe added a note Mar 27, 2013

When we change this, there shouldn't be a reference to the first model creating a MetaData object in CActiveRecordMetaData.
Should be refactored to store only the class name instead of the model as it is not needed there anyway.
See CActiveRecordMetaData line 2300, 2361 and constructor.

Yii Software LLC member
klimov-paul added a note Mar 28, 2013


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
cebe and others added some commits Mar 27, 2013
@cebe cebe Merge branch 'Rupert-RR-2131-add-accept-header-parsing'
* Rupert-RR-2131-add-accept-header-parsing:
  php doc adjustments after #2132
  Yii code style correction
  Removed unnecessary spaces.
  Transferred data for unit tests from the test functions into data providers.
  Undo accidental permissions change on bootstrap.php
  Added unit test file for CHttpRequest for the methods parseAcceptHeader() and compareAcceptTypes(). Modified the regexp in parseAcceptHeader() to accept wildcards in the path. Modified the description of compareAcceptTypes() to better reflect the comparison result (higher preference returns lower value, so that most preferred is first in the array).
  parseAcceptHeader() function description tidy up.
  Typo corrections and code tidy up.
  Altered parseAcceptHeader() to use only one regexp. Thanks to Ka on StackExchange for this expression.
  Typo corrections
  Separated out parse and compare functions. Reduced regular expression count to 2 from 3. Modified MIME type array map structure.
  Added #135 back in changelog, which got lost somehow..
  Moved position of line to follow numerical order.
  Enh #2131: Added Accept header parsing to CHttpRequest to give an array of accepted types in order of preference
@klimov-paul klimov-paul Merge branch '2251-refactor-active-record-meta-data' of…
…imov-paul/yii into 2251-refactor-active-record-meta-data
@klimov-paul klimov-paul Extra "CActiveRecordMetaData::$_model" field has been removed. cb05e18
@klimov-paul klimov-paul Code indenting at "CActiveRecordMetaData" has been fixed. d800c0f
Yii Software LLC member

PR update.
However it shows some Yii master commits as own changes.
I have no idea why this happens. Could it be a problem?

Yii Software LLC member
samdark commented Mar 28, 2013

Possibly. This one should be merged manually it least with verifying that everything is OK.

Yii Software LLC member

Migrated to #2269

Yii Software LLC member
cebe commented Mar 28, 2013

I have no idea why this happens. Could it be a problem?

Don't think there is a problem with it, git will handle it just right, only thing is a weird behavior of github which shows commits that do not belong here. reported it to GH support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.