From: Evan Prodromou Date: Tue, 2 Aug 2011 22:12:46 +0000 (-0400) Subject: only do a db call if need to fetch some in listGet() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=447ae92eca531f76c7ec2d09743496fd9b3460de;p=quix0rs-gnu-social.git only do a db call if need to fetch some in listGet() --- diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 5115cf7520..e1610c56b2 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -171,25 +171,26 @@ class Memcached_DataObject extends Safe_DataObject $toFetch[] = $keyVal; } } - - $i = DB_DataObject::factory($cls); - if (empty($i)) { - throw new Exception(_('Cannot instantiate class ' . $cls)); - } - $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol)); - if ($i->find()) { - while ($i->fetch()) { - $copy = clone($i); - $copy->encache(); - $result[$i->$keyCol][] = $copy; - } - } - - foreach ($toFetch as $keyVal) - { - self::cacheSet(sprintf("%s:list:%s:%s", $cls, $keyCol, $keyVal), - $result[$keyVal]); - } + + if (count($toFetch) > 0) { + $i = DB_DataObject::factory($cls); + if (empty($i)) { + throw new Exception(_('Cannot instantiate class ' . $cls)); + } + $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol)); + if ($i->find()) { + while ($i->fetch()) { + $copy = clone($i); + $copy->encache(); + $result[$i->$keyCol][] = $copy; + } + } + foreach ($toFetch as $keyVal) + { + self::cacheSet(sprintf("%s:list:%s:%s", $cls, $keyCol, $keyVal), + $result[$keyVal]); + } + } return $result; }