summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/Notice.php106
-rw-r--r--classes/Notice_inbox.php56
2 files changed, 102 insertions, 60 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 49d0939c1..6a7522bd3 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -635,25 +635,58 @@ class Notice extends Memcached_DataObject
function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
{
+ $ids = Notice::stream(array('Notice', '_publicStreamDirect'),
+ array(),
+ 'public',
+ $offset, $limit, $since_id, $before_id, $since);
- $parts = array();
+ return Notice::getStreamByIds($ids);
+ }
+
+ function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
+ {
+ $notice = new Notice();
+
+ $notice->selectAdd(); // clears it
+ $notice->selectAdd('id');
- $qry = 'SELECT * FROM notice ';
+ $notice->orderBy('id DESC');
+
+ if (!is_null($offset)) {
+ $notice->limit($offset, $limit);
+ }
if (common_config('public', 'localonly')) {
- $parts[] = 'is_local = 1';
+ $notice->whereAdd('is_local = 1');
} else {
# -1 == blacklisted
- $parts[] = 'is_local != -1';
+ $notice->whereAdd('is_local != -1');
+ }
+
+ if ($since_id != 0) {
+ $notice->whereAdd('id > ' . $since_id);
+ }
+
+ if ($before_id != 0) {
+ $notice->whereAdd('id < ' . $before_id);
}
- if ($parts) {
- $qry .= ' WHERE ' . implode(' AND ', $parts);
+ if (!is_null($since)) {
+ $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
}
- return Notice::getStream($qry,
- 'public',
- $offset, $limit, $since_id, $before_id, null, $since);
+ $ids = array();
+
+ if ($notice->find()) {
+ while ($notice->fetch()) {
+ $ids[] = $notice->id;
+ }
+ }
+
+ $notice->free();
+ $notice = NULL;
+
+ return $ids;
}
function addToInboxes()
@@ -967,4 +1000,59 @@ class Notice extends Memcached_DataObject
array('notice' => $this->id));
}
}
+
+ function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
+ {
+ $cache = common_memcache();
+
+ if (empty($cache) ||
+ $since_id != 0 || $before_id != 0 || !is_null($since) ||
+ ($offset + $limit) > NOTICE_CACHE_WINDOW) {
+ return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id,
+ $before_id, $since)));
+ }
+
+ $idkey = common_cache_key($cachekey);
+
+ $idstr = $cache->get($idkey);
+
+ if (!empty($idstr)) {
+ // Cache hit! Woohoo!
+ $window = explode(',', $idstr);
+ $ids = array_slice($window, $offset, $limit);
+ return $ids;
+ }
+
+ $laststr = $cache->get($idkey.';last');
+
+ if (!empty($laststr)) {
+ $window = explode(',', $laststr);
+ $last_id = $window[0];
+ $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
+ $last_id, 0, null)));
+
+ $new_window = array_merge($new_ids, $window);
+
+ $new_windowstr = implode(',', $new_window);
+
+ $result = $cache->set($idkey, $new_windowstr);
+ $result = $cache->set($idkey . ';last', $new_windowstr);
+
+ $ids = array_slice($new_window, $offset, $limit);
+
+ return $ids;
+ }
+
+ $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
+ 0, 0, null)));
+
+ $windowstr = implode(',', $window);
+
+ $result = $cache->set($idkey, $windowstr);
+ $result = $cache->set($idkey . ';last', $windowstr);
+
+ $ids = array_slice($window, $offset, $limit);
+
+ return $ids;
+ }
}
diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php
index f32137038..dec14b0d1 100644
--- a/classes/Notice_inbox.php
+++ b/classes/Notice_inbox.php
@@ -43,58 +43,12 @@ class Notice_inbox extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function stream($user_id, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
+ function stream($user_id, $offset, $limit, $since_id, $before_id, $since)
{
- $cache = common_memcache();
-
- if (empty($cache) ||
- $since_id != 0 || $before_id != 0 || !is_null($since) ||
- ($offset + $limit) > INBOX_CACHE_WINDOW) {
- return Notice_inbox::_streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since);
- }
-
- $idkey = common_cache_key('notice_inbox:by_user:'.$user_id);
-
- $idstr = $cache->get($idkey);
-
- if (!empty($idstr)) {
- // Cache hit! Woohoo!
- $window = explode(',', $idstr);
- $ids = array_slice($window, $offset, $limit);
- return $ids;
- }
-
- $laststr = common_cache_key($idkey.';last');
-
- if (!empty($laststr)) {
- $window = explode(',', $laststr);
- $last_id = $window[0];
- $new_ids = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW,
- $last_id, null, null);
-
- $new_window = array_merge($new_ids, $window);
-
- $new_windowstr = implode(',', $new_window);
-
- $result = $cache->set($idkey, $new_windowstr);
- $result = $cache->set($idkey . ';last', $new_windowstr);
-
- $ids = array_slice($new_window, $offset, $limit);
-
- return $ids;
- }
-
- $window = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW,
- null, null, null);
-
- $windowstr = implode(',', $new_window);
-
- $result = $cache->set($idkey, $windowstr);
- $result = $cache->set($idkey . ';last', $windowstr);
-
- $ids = array_slice($window, $offset, $limit);
-
- return $ids;
+ return Notice::stream(array('Notice_inbox', '_streamDirect'),
+ array($user_id),
+ 'notice_inbox:by_user:'.$user_id,
+ $offset, $limit, $since_id, $before_id, $since);
}
function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since)