only do a db call if need to fetch some in listGet()

This commit is contained in:
Evan Prodromou 2011-08-02 18:12:46 -04:00
parent 435c08a753
commit 447ae92eca

View File

@ -172,24 +172,25 @@ class Memcached_DataObject extends Safe_DataObject
} }
} }
$i = DB_DataObject::factory($cls); if (count($toFetch) > 0) {
if (empty($i)) { $i = DB_DataObject::factory($cls);
throw new Exception(_('Cannot instantiate class ' . $cls)); if (empty($i)) {
} throw new Exception(_('Cannot instantiate class ' . $cls));
$i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol)); }
if ($i->find()) { $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
while ($i->fetch()) { if ($i->find()) {
$copy = clone($i); while ($i->fetch()) {
$copy->encache(); $copy = clone($i);
$result[$i->$keyCol][] = $copy; $copy->encache();
$result[$i->$keyCol][] = $copy;
}
} }
} foreach ($toFetch as $keyVal)
{
foreach ($toFetch as $keyVal) self::cacheSet(sprintf("%s:list:%s:%s", $cls, $keyCol, $keyVal),
{ $result[$keyVal]);
self::cacheSet(sprintf("%s:list:%s:%s", $cls, $keyCol, $keyVal), }
$result[$keyVal]); }
}
return $result; return $result;
} }