]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge remote-tracking branch 'gitorious/1.0.x' into 1.0.x
authorEvan Prodromou <evan@status.net>
Thu, 14 Jul 2011 16:54:45 +0000 (12:54 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 14 Jul 2011 16:54:45 +0000 (12:54 -0400)
classes/Memcached_DataObject.php
classes/Notice.php
lib/conversationnoticestream.php
lib/noticestream.php

index 0e60b7fed586ecc3143aefaff0366bda4469f950..f1336e582fc528f987f50cc500b0d0e943b65187 100644 (file)
@@ -63,7 +63,56 @@ class Memcached_DataObject extends Safe_DataObject
         }
         return $i;
     }
+    
+    function multiGet($cls, $keyCol, $keyVals)
+    {
+       $result = array_fill_keys($keyVals, null);
+       
+       $toFetch = array();
+       
+       foreach ($keyVals as $keyVal) {
+               $i = self::getcached($cls, $keyCol, $keyVal);
+               if ($i !== false) {
+                       $result[$keyVal] = $i;
+               } else if (!empty($keyVal)) {
+                       $toFetch[] = $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;
+                       }
+               }
+       }
+       
+       return new ArrayWrapper(array_values($result));
+    }
 
+       function columnType($columnName)
+       {
+               $keys = $this->table();
+               if (!array_key_exists($columnName, $keys)) {
+                       throw new Exception('Unknown key column ' . $columnName . ' in ' . join(',', array_keys($keys)));
+               }
+               
+               $def = $keys[$columnName];
+               
+               if ($def & DB_DATAOBJECT_INT) {
+                       return 'integer';
+               } else {
+                       return 'string';
+               }
+       }
+       
     /**
      * @fixme Should this return false on lookup fail to match staticGet?
      */
index 29824ab700587eef371e1737d834914c2f332dd3..4476798661eef7149c98652a20add7230b7aa9c7 100644 (file)
@@ -84,6 +84,11 @@ class Notice extends Memcached_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
+       function multiGet($kc, $kvs)
+       {
+               return Memcached_DataObject::multiGet('Notice', $kc, $kvs);
+       }
+       
     /* Notice types */
     const LOCAL_PUBLIC    =  1;
     const REMOTE_OMB      =  0;
@@ -1856,7 +1861,11 @@ class Notice extends Memcached_DataObject
         } else {
             $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
             if ($idstr !== false) {
-                $ids = explode(',', $idstr);
+               if (empty($idstr)) {
+                       $ids = array();
+               } else {
+                       $ids = explode(',', $idstr);
+               }
             } else {
                 $ids = $this->_repeatStreamDirect(100);
                 $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
@@ -1885,18 +1894,7 @@ class Notice extends Memcached_DataObject
             $notice->limit(0, $limit);
         }
 
-        $ids = array();
-
-        if ($notice->find()) {
-            while ($notice->fetch()) {
-                $ids[] = $notice->id;
-            }
-        }
-
-        $notice->free();
-        $notice = NULL;
-
-        return $ids;
+        return $notice->fetchAll('id');
     }
 
     function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
index 66075db84f436a62c095174f0036b8231fddf4a5..adf610ffe7b2841c0d15260cc093b3d0216a573b 100644 (file)
@@ -95,14 +95,6 @@ class RawConversationNoticeStream extends NoticeStream
         Notice::addWhereSinceId($notice, $since_id);
         Notice::addWhereMaxId($notice, $max_id);
 
-        $ids = array();
-
-        if ($notice->find()) {
-            while ($notice->fetch()) {
-                $ids[] = $notice->id;
-            }
-        }
-
-        return $ids;
+        return $notice->fetchAll('id');
     }
 }
\ No newline at end of file
index be28aa61867526f56214ca9ed7f9f6b9534e20a7..e9ff47b68c154eb73641cbaf97dbb1b0126c2cae 100644 (file)
@@ -59,42 +59,6 @@ abstract class NoticeStream
 
     static function getStreamByIds($ids)
     {
-        $cache = Cache::instance();
-
-        if (!empty($cache)) {
-            $notices = array();
-            foreach ($ids as $id) {
-                $n = Notice::staticGet('id', $id);
-                if (!empty($n)) {
-                    $notices[] = $n;
-                }
-            }
-            return new ArrayWrapper($notices);
-        } else {
-            $notice = new Notice();
-            if (empty($ids)) {
-                //if no IDs requested, just return the notice object
-                return $notice;
-            }
-            $notice->whereAdd('id in (' . implode(', ', $ids) . ')');
-
-            $notice->find();
-
-            $temp = array();
-
-            while ($notice->fetch()) {
-                $temp[$notice->id] = clone($notice);
-            }
-
-            $wrapped = array();
-
-            foreach ($ids as $id) {
-                if (array_key_exists($id, $temp)) {
-                    $wrapped[] = $temp[$id];
-                }
-            }
-
-            return new ArrayWrapper($wrapped);
-        }
+       return Notice::multiGet('id', $ids);
     }
 }