mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Track tokenizer cache hits / misses
Change-Id: I65d4c6064c37e9957b6f0aca4d3032f26bdf9bde
This commit is contained in:
parent
ec66d99d9d
commit
ecbd159ce5
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue