]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Memcached_DataObject.php
Merge remote-tracking branch 'gitorious/1.0.x' into 1.0.x
[quix0rs-gnu-social.git] / classes / Memcached_DataObject.php
index 11be6c7c27c8fd8a766f1ba505a433c224b9cb9c..b857ae64b9fdfe79a6a9fdd5417b946963024229 100644 (file)
@@ -63,44 +63,44 @@ class Memcached_DataObject extends Safe_DataObject
         }
         return $i;
     }
-    
+
     /**
      * Get multiple items from the database by key
-     * 
+     *
      * @param string  $cls       Class to fetch
      * @param string  $keyCol    name of column for key
      * @param array   $keyVals   key values to fetch
      * @param boolean $skipNulls return only non-null results?
-     * 
+     *
      * @return array Array of objects, in order
      */
     function multiGet($cls, $keyCol, $keyVals, $skipNulls=true)
     {
-       $result = self::pivotGet($cls, $keyCol, $keyVals);
-       
-       $values = array_values($result);
-       
-       if ($skipNulls) {
-               $tmp = array();
-               foreach ($values as $value) {
-                       if (!empty($value)) {
-                               $tmp[] = $value;
-                       }
-               }
-               $values = $tmp;
-       }
-       
-       return new ArrayWrapper($values);
+        $result = self::pivotGet($cls, $keyCol, $keyVals);
+
+        $values = array_values($result);
+
+        if ($skipNulls) {
+            $tmp = array();
+            foreach ($values as $value) {
+                if (!empty($value)) {
+                    $tmp[] = $value;
+                }
+            }
+            $values = $tmp;
+        }
+
+        return new ArrayWrapper($values);
     }
-    
+
     /**
      * Get multiple items from the database by key
-     * 
+     *
      * @param string  $cls       Class to fetch
      * @param string  $keyCol    name of column for key
      * @param array   $keyVals   key values to fetch
      * @param boolean $otherCols Other columns to hold fixed
-     * 
+     *
      * @return array Array mapping $keyVals to objects, or null if not found
      */
     static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
@@ -267,10 +267,10 @@ class Memcached_DataObject extends Safe_DataObject
     function listGet($cls, $keyCol, $keyVals)
     {
        $pkeyMap = array_fill_keys($keyVals, array());
-        $results = array_fill_keys($keyVals, array());
+        $result = array_fill_keys($keyVals, array());
 
         $pkeyCols = self::pkeyCols($cls);
-        
+
        $toFetch = array();
         $allPkeys = array();
 
@@ -280,19 +280,23 @@ class Memcached_DataObject extends Safe_DataObject
            $l = self::cacheGet(sprintf("%s:list-ids:%s:%s", $cls, $keyCol, $keyVal));
            if ($l !== false) {
                $pkeyMap[$keyVal] = $l;
-                $allPkeys = array_merge($allPkeys, $l);
+                foreach ($l as $pkey) {
+                    $allPkeys[] = $pkey;
+                }
            } else {
                $toFetch[] = $keyVal;
            }
        }
 
-        $keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
+        if (count($allPkeys) > 0) {
+            $keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
 
-        foreach ($pkeyMap as $keyVal => $pkeyList) {
-            foreach ($pkeyList as $pkeyVal) {
-                $i = $keyResults[$pkeyVal];
-                if (!empty($i)) {
-                    $results[$keyVal][] = $i;
+            foreach ($pkeyMap as $keyVal => $pkeyList) {
+                foreach ($pkeyList as $pkeyVal) {
+                    $i = $keyResults[implode(',',$pkeyVal)];
+                    if (!empty($i)) {
+                        $result[$keyVal][] = $i;
+                    }
                 }
             }
         }
@@ -304,6 +308,7 @@ class Memcached_DataObject extends Safe_DataObject
                }
             $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
             if ($i->find()) {
+                sprintf("listGet() got {$i->N} results for class $cls key $keyCol");
                 while ($i->fetch()) {
                     $copy = clone($i);
                     $copy->encache();
@@ -320,7 +325,7 @@ class Memcached_DataObject extends Safe_DataObject
                                $pkeyMap[$keyVal]);
             }      
         }
-       
+
        return $result;        
     }
 
@@ -341,7 +346,7 @@ class Memcached_DataObject extends Safe_DataObject
        }
        
     /**
-     * @fixme Should this return false on lookup fail to match staticGet?
+     * @todo FIXME: Should this return false on lookup fail to match staticGet?
      */
     function pkeyGet($cls, $kv)
     {
@@ -354,13 +359,13 @@ class Memcached_DataObject extends Safe_DataObject
                 return false;
             }
             foreach ($kv as $k => $v) {
-               if (is_null($v)) {
-                       // XXX: possible SQL injection...? Don't 
-                       // pass keys from the browser, eh.
-                       $i->whereAdd("$k is null");
-               } else {
-                       $i->$k = $v;
-               }
+                if (is_null($v)) {
+                    // XXX: possible SQL injection...? Don't
+                    // pass keys from the browser, eh.
+                    $i->whereAdd("$k is null");
+                } else {
+                    $i->$k = $v;
+                }
             }
             if ($i->find(true)) {
                 $i->encache();
@@ -691,7 +696,7 @@ class Memcached_DataObject extends Safe_DataObject
                     continue;
                 }
                 if (in_array($func, $ignoreStatic)) {
-                    continue; // @fixme this shouldn't be needed?
+                    continue; // @todo FIXME: This shouldn't be needed?
                 }
                 $here = get_class($frame['object']) . '->' . $func;
                 break;
@@ -834,7 +839,7 @@ class Memcached_DataObject extends Safe_DataObject
 
         if (!$dsn) {
             // TRANS: Exception thrown when database name or Data Source Name could not be found.
-            throw new Exception(_("No database name or DSN found anywhere."));
+            throw new Exception(_('No database name or DSN found anywhere.'));
         }
 
         return $dsn;