summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-14 16:41:25 -0500
committerEvan Prodromou <evan@status.net>2009-12-14 16:41:25 -0500
commit2a8eee0e0b33ce15289484270d3211f502940920 (patch)
treec854dc0228f8d31086329ba4eb5e7e6059079469 /classes
parent9384a6e2429d8ef9a68185c869758b1e258092c1 (diff)
add friends_timeline with no repeats in it
Diffstat (limited to 'classes')
-rw-r--r--classes/Notice.php18
-rw-r--r--classes/User.php71
2 files changed, 89 insertions, 0 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 66d9cf5d4..4aec4ed55 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -530,8 +530,18 @@ class Notice extends Memcached_DataObject
if ($member->find()) {
while ($member->fetch()) {
$cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id));
+ $cache->delete(common_cache_key('notice_inbox:by_user_own:' . $member->profile_id));
+ if (empty($this->repeat_of)) {
+ $cache->delete(common_cache_key('user:friends_timeline:' . $member->profile_id));
+ $cache->delete(common_cache_key('user:friends_timeline_own:' . $member->profile_id));
+ }
if ($blowLast) {
$cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id . ';last'));
+ $cache->delete(common_cache_key('notice_inbox:by_user_own:' . $member->profile_id . ';last'));
+ if (empty($this->repeat_of)) {
+ $cache->delete(common_cache_key('user:friends_timeline:' . $member->profile_id . ';last'));
+ $cache->delete(common_cache_key('user:friends_timeline_own:' . $member->profile_id . ';last'));
+ }
}
}
}
@@ -579,9 +589,17 @@ class Notice extends Memcached_DataObject
while ($user->fetch()) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id));
$cache->delete(common_cache_key('notice_inbox:by_user_own:'.$user->id));
+ if (empty($this->repeat_of)) {
+ $cache->delete(common_cache_key('user:friends_timeline:'.$user->id));
+ $cache->delete(common_cache_key('user:friends_timeline_own:'.$user->id));
+ }
if ($blowLast) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last'));
$cache->delete(common_cache_key('notice_inbox:by_user_own:'.$user->id.';last'));
+ if (empty($this->repeat_of)) {
+ $cache->delete(common_cache_key('user:friends_timeline:'.$user->id.';last'));
+ $cache->delete(common_cache_key('user:friends_timeline_own:'.$user->id.';last'));
+ }
}
}
$user->free();
diff --git a/classes/User.php b/classes/User.php
index 9c071e06b..d04f7d679 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -473,6 +473,77 @@ class User extends Memcached_DataObject
return Notice::getStreamByIds($ids);
}
+ function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+ {
+ $ids = Notice::stream(array($this, '_friendsTimelineDirect'),
+ array(false),
+ 'user:friends_timeline:'.$this->id,
+ $offset, $limit, $since_id, $before_id, $since);
+
+ return Notice::getStreamByIds($ids);
+ }
+
+ function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+ {
+ $ids = Notice::stream(array($this, '_friendsTimelineDirect'),
+ array(true),
+ 'user:friends_timeline_own:'.$this->id,
+ $offset, $limit, $since_id, $before_id, $since);
+
+ return Notice::getStreamByIds($ids);
+ }
+
+ function _friendsTimelineDirect($own, $offset, $limit, $since_id, $max_id, $since)
+ {
+ $qry =
+ 'SELECT notice.id AS id ' .
+ 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
+ 'WHERE notice_inbox.user_id = ' . $this->id . ' ' .
+ 'AND notice.repeat_of IS NULL ';
+
+ if (!$own) {
+ // XXX: autoload notice inbox for constant
+ $inbox = new Notice_inbox();
+
+ $qry .= 'AND notice_inbox.source != ' . NOTICE_INBOX_SOURCE_GATEWAY . ' ';
+ }
+
+ if ($since_id != 0) {
+ $qry .= 'AND notice.id > ' . $since_id . ' ';
+ }
+
+ if ($max_id != 0) {
+ $qry .= 'AND notice.id <= ' . $max_id . ' ';
+ }
+
+ if (!is_null($since)) {
+ $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
+ }
+
+ // NOTE: we sort by fave time, not by notice time!
+
+ $qry .= 'ORDER BY notice.id DESC ';
+
+ if (!is_null($offset)) {
+ $qry .= "LIMIT $limit OFFSET $offset";
+ }
+
+ $ids = array();
+
+ $notice = new Notice();
+
+ $notice->query($qry);
+
+ while ($notice->fetch()) {
+ $ids[] = $notice->id;
+ }
+
+ $notice->free();
+ $notice = NULL;
+
+ return $ids;
+ }
+
function blowFavesCache()
{
$cache = common_memcache();