blow subscriptions cache when the user deletes a notice

darcs-hash:20080920175339-84dde-e46d0e7b86e0752e8331cdfba26257b3ff9e601c.gz
This commit is contained in:
Evan Prodromou 2008-09-20 13:53:39 -04:00
parent d53a4123f3
commit a64330b77c
2 changed files with 22 additions and 15 deletions

View File

@ -84,6 +84,9 @@ class DeletenoticeAction extends DeleteAction {
$replies->get('notice_id', $notice_id); $replies->get('notice_id', $notice_id);
common_dequeue_notice($notice); common_dequeue_notice($notice);
if (common_config('memcached', 'enabled')) {
$notice->blowSubsCache();
}
$replies->delete(); $replies->delete();
$notice->delete(); $notice->delete();
} else { } else {

View File

@ -116,23 +116,27 @@ class Notice extends DB_DataObject
# XXX: someone clever could prepend instead of clearing the cache # XXX: someone clever could prepend instead of clearing the cache
if (common_config('memcached', 'enabled')) { if (common_config('memcached', 'enabled')) {
$cache = new Memcache(); $notice->blowSubsCache();
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
$user = new User();
$user->query('SELECT id ' .
'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
'WHERE subscription.subscribed = ' . $notice->profile_id);
while ($user->fetch()) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
}
$user->free();
unset($user);
}
} }
return $notice; return $notice;
} }
function blowSubsCache() {
$cache = new Memcache();
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
$user = new User();
$user->query('SELECT id ' .
'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
'WHERE subscription.subscribed = ' . $this->profile_id);
while ($user->fetch()) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
}
$user->free();
unset($user);
}
}
} }