From 53f03e5301a6f2484eab6039fb8cf3d4772408d0 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 28 May 2019 10:11:03 +0200 Subject: [PATCH] Tokenizer caching back to APC Partial revert of I4dd81a723e2bdb828b90594ad66a3918d8ec5b6c. Thinking again of it, I think it's not worth it to have this data over the network. Plus, given that it's not-that-slow to be computed, I think there can only be a performance gain in using APC (as opposed to e.g. memcached/redis) for 99.9% of the filters. Change-Id: I8c6a4a95ec12c18ede8e6419540f7a2ac943457c --- includes/parser/AbuseFilterTokenizer.php | 15 ++++++--------- tests/phpunit/AbuseFilterTokenizerTest.php | 14 +++----------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/includes/parser/AbuseFilterTokenizer.php b/includes/parser/AbuseFilterTokenizer.php index 6f81afa10..807c400a1 100644 --- a/includes/parser/AbuseFilterTokenizer.php +++ b/includes/parser/AbuseFilterTokenizer.php @@ -1,7 +1,5 @@ makeGlobalKey( __CLASS__, crc32( $code ) ); + public static function getCacheKey( BagOStuff $cache, $code ) { + return $cache->makeGlobalKey( __CLASS__, self::CACHE_VERSION, crc32( $code ) ); } /** @@ -85,15 +83,14 @@ class AbuseFilterTokenizer { * @return array[] */ public static function getTokens( $code ) { - $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $cache = ObjectCache::getLocalServerInstance( 'hash' ); $tokens = $cache->getWithSetCallback( self::getCacheKey( $cache, $code ), $cache::TTL_DAY, - function ( $oldValue, &$ttl, array &$setOpts ) use ( $code ) { + function () use ( $code ) { return self::tokenize( $code ); - }, - [ 'version' => self::CACHE_VERSION ] + } ); return $tokens; diff --git a/tests/phpunit/AbuseFilterTokenizerTest.php b/tests/phpunit/AbuseFilterTokenizerTest.php index 095ce6771..95aba017b 100644 --- a/tests/phpunit/AbuseFilterTokenizerTest.php +++ b/tests/phpunit/AbuseFilterTokenizerTest.php @@ -117,23 +117,15 @@ class AbuseFilterTokenizerTest extends AbuseFilterParserTestCase { * @dataProvider provideCode */ public function testCaching( $code ) { - $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); - $this->setService( 'MainWANObjectCache', $cache ); + $cache = new HashBagOStuff(); + $this->setService( 'LocalServerObjectCache', $cache ); $key = AbuseFilterTokenizer::getCacheKey( $cache, $code ); // Other tests may have already cached the same code. $cache->delete( $key ); AbuseFilterTokenizer::getTokens( $code ); - $cached = $cache->getWithSetCallback( - $key, - $cache::TTL_DAY, - function () { - return false; - }, - [ 'version' => 1 ] - ); - $this->assertNotFalse( $cached ); + $this->assertNotFalse( $cache->get( $key ) ); } /**