}
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?
*/
/* 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;
} 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));
$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)
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
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);
}
}