edit throttling
darcs-hash:20081210174722-84dde-4c79d7f73230d008195bd19738bc9a6017b940e9.gz
This commit is contained in:
parent
1c0a19b457
commit
a143b64666
@ -93,6 +93,11 @@ class Notice extends Memcached_DataObject
|
||||
|
||||
static function saveNew($profile_id, $content, $source=NULL, $is_local=1, $reply_to=NULL, $uri=NULL) {
|
||||
|
||||
if (!Notice::checkEditThrottle($profile_id)) {
|
||||
common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
|
||||
return _('Too many notices too fast; take a breather and post again in a few minutes.');
|
||||
}
|
||||
|
||||
$notice = new Notice();
|
||||
$notice->profile_id = $profile_id;
|
||||
|
||||
@ -147,6 +152,24 @@ class Notice extends Memcached_DataObject
|
||||
return $notice;
|
||||
}
|
||||
|
||||
static function checkEditThrottle($profile_id) {
|
||||
$profile = Profile::staticGet($profile_id);
|
||||
if (!$profile) {
|
||||
return false;
|
||||
}
|
||||
# Get the Nth notice
|
||||
$notice = $profile->getNotices(common_config('throttle', 'count') - 1, 1);
|
||||
if ($notice && $notice->fetch()) {
|
||||
# If the Nth notice was posted less than timespan seconds ago
|
||||
if (time() - strtotime($notice->created) <= common_config('throttle', 'timespan')) {
|
||||
# Then we throttle
|
||||
return false;
|
||||
}
|
||||
}
|
||||
# Either not N notices in the stream, OR the Nth was not posted within timespan seconds
|
||||
return true;
|
||||
}
|
||||
|
||||
function blowCaches($blowLast=false) {
|
||||
$this->blowSubsCache($blowLast);
|
||||
$this->blowNoticeCache($blowLast);
|
||||
@ -197,9 +220,9 @@ class Notice extends Memcached_DataObject
|
||||
if ($this->is_local) {
|
||||
$cache = common_memcache();
|
||||
if ($cache) {
|
||||
$cache->delete(common_cache_key('user:notices:'.$this->profile_id));
|
||||
$cache->delete(common_cache_key('profile:notices:'.$this->profile_id));
|
||||
if ($blowLast) {
|
||||
$cache->delete(common_cache_key('user:notices:'.$this->profile_id.';last'));
|
||||
$cache->delete(common_cache_key('profile:notices:'.$this->profile_id.';last'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,4 +145,15 @@ class Profile extends Memcached_DataObject
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
|
||||
$qry =
|
||||
'SELECT * ' .
|
||||
'FROM notice ' .
|
||||
'WHERE profile_id = %d ';
|
||||
|
||||
return Notice::getStream(sprintf($qry, $this->id),
|
||||
'profile:notices:'.$this->id,
|
||||
$offset, $limit, $since_id, $before_id);
|
||||
}
|
||||
}
|
||||
|
@ -342,14 +342,12 @@ class User extends Memcached_DataObject
|
||||
}
|
||||
|
||||
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
|
||||
$qry =
|
||||
'SELECT * ' .
|
||||
'FROM notice ' .
|
||||
'WHERE profile_id = %d ';
|
||||
|
||||
return Notice::getStream(sprintf($qry, $this->id),
|
||||
'user:notices:'.$this->id,
|
||||
$offset, $limit, $since_id, $before_id);
|
||||
$profile = $this->getProfile();
|
||||
if (!$profile) {
|
||||
return NULL;
|
||||
} else {
|
||||
return $profile->getNotices($offset, $limit, $since_id, $before_id);
|
||||
}
|
||||
}
|
||||
|
||||
function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE) {
|
||||
|
@ -61,7 +61,6 @@ $config['sphinx']['enabled'] = false;
|
||||
$config['sphinx']['server'] = 'localhost';
|
||||
$config['sphinx']['port'] = 3312;
|
||||
|
||||
|
||||
# Users to populate the 'Featured' tab
|
||||
#$config['nickname']['featured'][] = 'scobleizer';
|
||||
|
||||
@ -93,7 +92,6 @@ $config['sphinx']['port'] = 3312;
|
||||
#For incoming email, if enabled. Defaults to site server name.
|
||||
#$config['mail']['domain'] = 'incoming.example.net';
|
||||
|
||||
|
||||
#exponential decay factor for tags, default 10 days
|
||||
#raise this if traffic is slow, lower it if it's fast
|
||||
#$config['tag']['dropoff'] = 86400.0 * 10;
|
||||
@ -124,3 +122,11 @@ $config['sphinx']['port'] = 3312;
|
||||
|
||||
#Twitter integration source attribute. Note: default is Laconica
|
||||
#$config['integration']['source'] = 'Laconica';
|
||||
|
||||
# Edit throttling. Off by default. If turned on, you can only post 20 notices
|
||||
# every 10 minutes. Admins may want to play with the settings to minimize inconvenience for
|
||||
# real users without getting uncontrollable floods from spammers or runaway bots.
|
||||
|
||||
#$config['throttle']['enabled'] = true;
|
||||
#$config['throttle']['count'] = 100;
|
||||
#$config['throttle']['timespan'] = 3600;
|
@ -92,6 +92,10 @@ $config =
|
||||
'blacklist' => array()),
|
||||
'theme' =>
|
||||
array('server' => NULL),
|
||||
'throttle' =>
|
||||
array('enabled' => false, // whether to throttle edits; false by default
|
||||
'count' => 20, // number of allowed messages in timespan
|
||||
'timespan' => 600), // timespan for throttling
|
||||
'xmpp' =>
|
||||
array('enabled' => false,
|
||||
'server' => 'INVALID SERVER',
|
||||
|
Loading…
Reference in New Issue
Block a user