Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created February 8, 2010 22:15
Show Gist options
  • Select an option

  • Save sminnee/298641 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/298641 to your computer and use it in GitHub Desktop.
Index: sapphire/core/model/DataObject.php
===================================================================
--- sapphire/core/model/DataObject.php (revision 98430)
+++ sapphire/core/model/DataObject.php (working copy)
@@ -1522,6 +1522,8 @@
}
}
+ private static $_cache_db = array();
+
/**
* Return all of the database fields defined in self::$db and all the parent classes.
* Doesn't include any fields specified by self::$has_one. Use $this->has_one() to get these fields
@@ -1534,22 +1536,17 @@
$good = false;
$items = array();
- foreach($classes as $class) {
- // Wait until after we reach DataObject
- if(!$good) {
- if($class == 'DataObject') {
- $good = true;
+ // Cache the combined data
+ if(!isset(self::$_cache_db[get_class($this)])) {
+ foreach($classes as $class) {
+ // Wait until after we reach DataObject
+ if(!$good) {
+ if($class == 'DataObject') {
+ $good = true;
+ }
+ continue;
}
- continue;
- }
- if($fieldName) {
- $db = Object::uninherited_static($class, 'db');
-
- if(isset($db[$fieldName])) {
- return $db[$fieldName];
- }
- } else {
$newItems = (array) Object::uninherited_static($class, 'db');
// Validate the data
foreach($newItems as $k => $v) {
@@ -1558,9 +1555,11 @@
}
$items = isset($items) ? array_merge((array)$items, $newItems) : $newItems;
}
+ self::$_cache_db[get_class($this)] = $items;
}
-
- return $items;
+
+ if($fieldName) return self::$_cache_db[get_class($this)][$fieldName];
+ else return self::$_cache_db[get_class($this)];
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment