Prune old edit stash entries from users as they create more
This should reduce pressure on certain medium-large sized memcached slabs. Pre-1.5 memcached versions have a harder time pruning expired entries in time to avoid evictions, so it will be most useful that scenario. Bug: T203786 Change-Id: Ic357dbfcd9abd525b02e8d631d1344db3745d24c
This commit is contained in:
parent
480c509de5
commit
c334883309
1 changed files with 25 additions and 0 deletions
|
|
@ -46,6 +46,8 @@ class ApiStashEdit extends ApiBase {
|
|||
const MAX_CACHE_TTL = 300; // 5 minutes
|
||||
const MAX_SIGNATURE_TTL = 60;
|
||||
|
||||
const MAX_CACHE_RECENT = 2;
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
$params = $this->extractRequestParams();
|
||||
|
|
@ -461,9 +463,32 @@ class ApiStashEdit extends ApiBase {
|
|||
);
|
||||
}
|
||||
|
||||
if ( $ok ) {
|
||||
// These blobs can waste slots in low cardinality memcached slabs
|
||||
self::pruneExcessStashedEntries( $cache, $user, $key );
|
||||
}
|
||||
|
||||
return $ok ? true : 'store_error';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BagOStuff $cache
|
||||
* @param User $user
|
||||
* @param string $newKey
|
||||
*/
|
||||
private static function pruneExcessStashedEntries( BagOStuff $cache, User $user, $newKey ) {
|
||||
$key = $cache->makeKey( 'stash-edit-recent', $user->getId() );
|
||||
|
||||
$keyList = $cache->get( $key ) ?: [];
|
||||
if ( count( $keyList ) >= self::MAX_CACHE_RECENT ) {
|
||||
$oldestKey = array_shift( $keyList );
|
||||
$cache->delete( $oldestKey );
|
||||
}
|
||||
|
||||
$keyList[] = $newKey;
|
||||
$cache->set( $key, $keyList, 2 * self::MAX_CACHE_TTL );
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return [
|
||||
'title' => [
|
||||
|
|
|
|||
Loading…
Reference in a new issue