Use only stored scores and pre-cache them

This commit is contained in:
Evan Prodromou 2012-03-21 13:21:14 -04:00
parent a1c2ec2c63
commit 69ec86a3dc

View File

@ -282,14 +282,15 @@ class ActivitySpamPlugin extends Plugin
return true; return true;
} }
function onEndNoticeInScope($notice, $profile, &$bResult) function onEndNoticeInScope($notice, $profile, &$bResult)
{ {
if ($this->hideSpam) { if ($this->hideSpam) {
if ($bResult) { if ($bResult) {
$score = $this->getScore($notice); $score = Spam_score::staticGet('notice_id', $notice->id);
if ($score->is_spam) { if (!empty($score) && $score->is_spam) {
if (empty($profile) || if (empty($profile) ||
($profile->id !== $notice->profile_id && ($profile->id !== $notice->profile_id &&
!$profile->hasRight(self::REVIEWSPAM))) { !$profile->hasRight(self::REVIEWSPAM))) {
@ -301,4 +302,17 @@ class ActivitySpamPlugin extends Plugin
return true; return true;
} }
/**
* Pre-cache our spam scores if needed.
*/
function onEndNoticeListPrefill(&$notices, &$profiles, $avatarSize) {
if ($this->hideSpam) {
foreach ($notices as $notice) {
$ids[] = $notice->id;
}
Memcached_DataObject::multiGet('Spam_score', 'notice_id', $ids);
}
return true;
}
} }