From: Aaron Schulz Date: Tue, 26 Mar 2019 05:26:13 +0000 (-0700) Subject: Prune old edit stash entries from users as they create more X-Git-Tag: 1.34.0-rc.0~2333^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/categories//%22?a=commitdiff_plain;h=c3348833097788dd8600e7e8cf826b217245633c;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php index 455ff458f1..fe5f6c4a44 100644 --- a/includes/api/ApiStashEdit.php +++ b/includes/api/ApiStashEdit.php @@ -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' => [