]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
only do a db call if need to fetch some in listGet()
authorEvan Prodromou <evan@status.net>
Tue, 2 Aug 2011 22:12:46 +0000 (18:12 -0400)
committerEvan Prodromou <evan@status.net>
Tue, 2 Aug 2011 22:12:46 +0000 (18:12 -0400)
classes/Memcached_DataObject.php

index 5115cf752017faa64d26aebc98f2ae74203b7242..e1610c56b214e34205c380dc1c187d2453c3c0a2 100644 (file)
@@ -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;        
     }