Commit ae340ec3 authored by Evan Prodromou's avatar Evan Prodromou

explicitly skip nulls in Memcached_DataObject::multiGet()

parent dc7099aa
......@@ -64,7 +64,17 @@ class Memcached_DataObject extends Safe_DataObject
return $i;
}
function multiGet($cls, $keyCol, $keyVals)
/**
* 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 = array_fill_keys($keyVals, null);
......@@ -92,9 +102,34 @@ class Memcached_DataObject extends Safe_DataObject
$result[$i->$keyCol] = $copy;
}
}
// Save state of DB misses
foreach ($toFetch as $keyVal) {
if (empty($result[$keyVal])) {
// save the fact that no such row exists
$c = self::memcache();
if (!empty($c)) {
$ck = self::cachekey($cls, $keyCol, $keyVal);
$c->set($ck, null);
}
}
}
}
$values = array_values($result);
if ($skipNulls) {
$tmp = array();
foreach ($values as $value) {
if (!empty($value)) {
$tmp[] = $value;
}
}
$values = $tmp;
}
return new ArrayWrapper(array_values($result));
return new ArrayWrapper($values);
}
function columnType($columnName)
......
......@@ -84,9 +84,9 @@ class Notice extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function multiGet($kc, $kvs)
function multiGet($kc, $kvs, $skipNulls=true)
{
return Memcached_DataObject::multiGet('Notice', $kc, $kvs);
return Memcached_DataObject::multiGet('Notice', $kc, $kvs, $skipNulls);
}
/* Notice types */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment