From ecbd159ce55de9adb274881a5d38bb3fe34557ce Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Thu, 22 Oct 2015 13:29:53 -0700 Subject: [PATCH] Track tokenizer cache hits / misses Change-Id: I65d4c6064c37e9957b6f0aca4d3032f26bdf9bde --- AbuseFilterTokenizer.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/AbuseFilterTokenizer.php b/AbuseFilterTokenizer.php index 728c851fa..3001d434d 100644 --- a/AbuseFilterTokenizer.php +++ b/AbuseFilterTokenizer.php @@ -67,22 +67,33 @@ class AbuseFilterTokenizer { $tokenizerCache = ObjectCache::newAccelerator( array(), 'hash' ); } + static $stats = null; + + if ( !$stats ) { + $stats = RequestContext::getMain()->getStats(); + } + $cacheKey = wfGlobalCacheKey( __CLASS__, self::CACHE_VERSION, crc32( $code ) ); + $tokens = $tokenizerCache->get( $cacheKey ); - if ( !$tokens ) { - $tokens = array(); - $curPos = 0; - - do { - $prevPos = $curPos; - $token = self::nextToken( $code, $curPos ); - $tokens[ $token->pos ] = array( $token, $curPos ); - } while ( $curPos !== $prevPos ); - - $tokenizerCache->set( $cacheKey, $tokens, 600 ); + if ( $tokens ) { + $stats->increment( 'AbuseFilter.tokenizerCache.hit' ); + return $tokens; } + $stats->increment( 'AbuseFilter.tokenizerCache.miss' ); + $tokens = array(); + $curPos = 0; + + do { + $prevPos = $curPos; + $token = self::nextToken( $code, $curPos ); + $tokens[ $token->pos ] = array( $token, $curPos ); + } while ( $curPos !== $prevPos ); + + $tokenizerCache->set( $cacheKey, $tokens, 600 ); + return $tokens; }