Track tokenizer cache hits / misses

Change-Id: I65d4c6064c37e9957b6f0aca4d3032f26bdf9bde
This commit is contained in:
Ori Livneh 2015-10-22 13:29:53 -07:00
parent ec66d99d9d
commit ecbd159ce5

View file

@ -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;
}