Clear ;last version of stream if importing old stuff

This commit is contained in:
Evan Prodromou 2011-03-31 16:15:05 -04:00
parent 61fe49b100
commit f580147058

View File

@ -445,19 +445,19 @@ class Notice extends Memcached_DataObject
function blowOnInsert($conversation = false) function blowOnInsert($conversation = false)
{ {
self::blow('profile:notice_ids:%d', $this->profile_id); $this->blowStream('profile:notice_ids:%d', $this->profile_id);
if ($this->isPublic()) { if ($this->isPublic()) {
self::blow('public'); $this->blowStream('public');
} }
// XXX: Before we were blowing the casche only if the notice id // XXX: Before we were blowing the casche only if the notice id
// was not the root of the conversation. What to do now? // was not the root of the conversation. What to do now?
self::blow('notice:conversation_ids:%d', $this->conversation); $this->blowStream('notice:conversation_ids:%d', $this->conversation);
if (!empty($this->repeat_of)) { if (!empty($this->repeat_of)) {
self::blow('notice:repeats:%d', $this->repeat_of); $this->blowStream('notice:repeats:%d', $this->repeat_of);
} }
$original = Notice::staticGet('id', $this->repeat_of); $original = Notice::staticGet('id', $this->repeat_of);
@ -465,11 +465,12 @@ class Notice extends Memcached_DataObject
if (!empty($original)) { if (!empty($original)) {
$originalUser = User::staticGet('id', $original->profile_id); $originalUser = User::staticGet('id', $original->profile_id);
if (!empty($originalUser)) { if (!empty($originalUser)) {
self::blow('user:repeats_of_me:%d', $originalUser->id); $this->blowStream('user:repeats_of_me:%d', $originalUser->id);
} }
} }
$profile = Profile::staticGet($this->profile_id); $profile = Profile::staticGet($this->profile_id);
if (!empty($profile)) { if (!empty($profile)) {
$profile->blowNoticeCount(); $profile->blowNoticeCount();
} }
@ -490,6 +491,42 @@ class Notice extends Memcached_DataObject
} }
} }
function blowStream()
{
$c = self::memcache();
if (empty($c)) {
return false;
}
$args = func_get_args();
$format = array_shift($args);
$keyPart = vsprintf($format, $args);
$cacheKey = Cache::key($keyPart);
$c->delete($cacheKey);
// delete the "last" stream, too, if this notice is
// older than the top of that stream
$lastKey = $cacheKey.';last';
$lastStr = $c->get($lastKey);
if ($lastStr !== false) {
$window = explode(',', $lastStr);
$lastID = $window[0];
$lastNotice = Notice::staticGet('id', $lastID);
if (empty($lastNotice) // just weird
|| strtotime($lastNotice->created) >= strtotime($this->created)) {
$c->delete($lastKey);
}
}
}
/** save all urls in the notice to the db /** save all urls in the notice to the db
* *
* follow redirects and save all available file information * follow redirects and save all available file information
@ -1513,22 +1550,22 @@ class Notice extends Memcached_DataObject
} }
$laststr = $cache->get($idkey.';last'); $laststr = $cache->get($idkey.';last');
if ($laststr !== false) { if ($laststr !== false) {
$window = explode(',', $laststr); $window = explode(',', $laststr);
$last_id = $window[0]; $last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
$last_id, 0, null))); $last_id, 0, null)));
$new_window = array_merge($new_ids, $window); $new_window = array_merge($new_ids, $window);
$new_windowstr = implode(',', $new_window); $new_windowstr = implode(',', $new_window);
$result = $cache->set($idkey, $new_windowstr); $result = $cache->set($idkey, $new_windowstr);
$result = $cache->set($idkey . ';last', $new_windowstr); $result = $cache->set($idkey . ';last', $new_windowstr);
$ids = array_slice($new_window, $offset, $limit); $ids = array_slice($new_window, $offset, $limit);
return $ids; return $ids;
} }