// 读取我的好友fids
$db = new DB();
$mc = new Memcached();
$_uid = 1; // my uid
$sql = "select * from follow where followuid={$_uid}";
$fbids = $db->fetchAll($sql);
// 缓存了每个用户的500条feed
function GetUserFeed($uid) {
$tbl = 'userfeed_' . ($uid % 8);
$sql = "select * from {$tbl} where uid={$uid}";
return $db->fetchAll($sql);
}
foreach ($fids as $fid) {
$result = GetUserFeed($uid);
$mc_key = "ck_user_feed_id_{$uid}";
$mc->set($mc_key, $result);
}
// 获取最新一条feed
function GetNewFeed($fids) {
$feed = '';
foreach ($fids as $fid) {
$tmp = $mc->get("ck_user_feed_id_{$fid}";
if (!$feed) {
$feed = $tmp;
continue;
} else {
if ($feed['createtime'] < $tmp['createtime']) {
$feed = $tmp
}
}
}
return $feed;
}