diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-14 01:19:05 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-14 01:19:05 +0000 |
commit | f439fe96c81930d0b7d43c02a3108fd15c17715e (patch) | |
tree | 3e7531df4c50d08ae318070fe9c553bd66ffbf22 | |
parent | 96d59caa3b32b58b10147f059047d13d57f24968 (diff) |
Overload ORM_Iterator to cache models as we pull them out of the
result set. This allows us to see the cache and avoid further
lookups.
-rw-r--r-- | core/helpers/model_cache.php | 6 | ||||
-rw-r--r-- | core/libraries/MY_ORM.php | 14 |
2 files changed, 20 insertions, 0 deletions
diff --git a/core/helpers/model_cache.php b/core/helpers/model_cache.php index d8158902..f4b11a6e 100644 --- a/core/helpers/model_cache.php +++ b/core/helpers/model_cache.php @@ -31,4 +31,10 @@ class model_cache_Core { return self::$cache->$model_name->$field_name->$id; } + + static function set($model) { + self::$cache->{$model->object_name} + ->{$model->primary_key} + ->{$model->{$model->primary_key}} = $model; + } } diff --git a/core/libraries/MY_ORM.php b/core/libraries/MY_ORM.php index 7c55b0c9..cc359799 100644 --- a/core/libraries/MY_ORM.php +++ b/core/libraries/MY_ORM.php @@ -28,3 +28,17 @@ class ORM extends ORM_Core { return $this; } } + +/** + * Slide this in here for convenience. We won't ever be overloading ORM_Iterator without ORM. + */ +class ORM_Iterator extends ORM_Iterator_Core { + /** + * Cache the result row + */ + public function current() { + $row = parent::current(); + model_cache::set($row); + return $row; + } +}
\ No newline at end of file |