make profile notice getting use ids

This commit is contained in:
Evan Prodromou 2009-05-01 11:27:57 -07:00
parent ec8dd014e3
commit 3328ec545c
2 changed files with 47 additions and 10 deletions

View File

@ -363,10 +363,10 @@ class Notice extends Memcached_DataObject
{ {
if ($this->is_local) { if ($this->is_local) {
$cache = common_memcache(); $cache = common_memcache();
if ($cache) { if (!empty($cache)) {
$cache->delete(common_cache_key('profile:notices:'.$this->profile_id)); $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id));
if ($blowLast) { if ($blowLast) {
$cache->delete(common_cache_key('profile:notices:'.$this->profile_id.';last')); $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id.';last'));
} }
} }
} }

View File

@ -155,14 +155,51 @@ class Profile extends Memcached_DataObject
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
{ {
$qry = // XXX: I'm not sure this is going to be any faster. It probably isn't.
'SELECT * ' . $ids = Notice::stream(array($this, '_streamDirect'),
'FROM notice ' . array(),
'WHERE profile_id = %d '; 'profile:notice_ids:' . $this->id,
$offset, $limit, $since_id, $before_id);
return Notice::getStream(sprintf($qry, $this->id), return Notice::getStreamByIds($ids);
'profile:notices:'.$this->id, }
$offset, $limit, $since_id, $before_id);
function _streamDirect($offset, $limit, $since_id, $before_id, $since)
{
$notice = new Notice();
$notice->profile_id = $this->id;
$notice->selectAdd();
$notice->selectAdd('id');
if ($since_id != 0) {
$notice->whereAdd('id > ' . $since_id);
}
if ($before_id != 0) {
$notice->whereAdd('id < ' . $before_id);
}
if (!is_null($since)) {
$notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
}
$notice->orderBy('id DESC');
if (!is_null($offset)) {
$notice->limit($offset, $limit);
}
$ids = array();
if ($notice->find()) {
while ($notice->fetch()) {
$ids[] = $notice->id;
}
}
return $ids;
} }
function isMember($group) function isMember($group)