DbObject: add prefetch stats for evaluation

This commit is contained in:
Thomas Gelf 2016-03-11 02:55:45 +01:00
parent c832ca4ade
commit 4fd4f0f7ce
1 changed files with 13 additions and 0 deletions

View File

@ -85,6 +85,8 @@ abstract class DbObject
*/
protected static $prefetchedNames = array();
protected static $prefetchStats = array();
/**
* Constructor is not accessible and should not be overridden
*/
@ -920,13 +922,24 @@ abstract class DbObject
return false;
$class = get_called_class();
if (! array_key_exists($class, self::$prefetchStats)) {
self::$prefetchStats[$class] = (object) array('miss' => 0, 'hits' => 0);
}
if (array_key_exists($class, self::$prefetched)) {
self::$prefetchStats[$class]->hits++;
return array_key_exists($key, self::$prefetched[$class]);
} else {
self::$prefetchStats[$class]->miss++;
return false;
}
}
public static function getPrefetchStats()
{
return self::$prefetchStats;
}
public static function loadWithAutoIncId($id, DbConnection $connection)
{
if ($prefetched = static::getPrefetched($id)) {