mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
synced 2024-11-15 02:03:58 +00:00
Use caching in TitleBlacklist::matches() for existing pages
The unicode normalization always shows up as a sizable chunk of call stack time in flame graphs. Change-Id: Iebbe6a90020d756e800ebf7b9b12d39b86190a48
This commit is contained in:
parent
cd9261c97f
commit
61dddceb86
|
@ -357,26 +357,40 @@ class TitleBlacklistEntry {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check whether a user can perform the specified action
|
||||
* on the specified Title
|
||||
* Check whether a user can perform the specified action on the specified Title
|
||||
*
|
||||
* @param $title string to check
|
||||
* @param $action %Action to check
|
||||
* @param string $title Title to check
|
||||
* @param string $action Action to check
|
||||
* @return bool TRUE if the the regex matches the title, and is not overridden
|
||||
* else false if it doesn't match (or was overridden)
|
||||
*/
|
||||
public function matches( $title, $action ) {
|
||||
if ( !$title ) {
|
||||
if ( $title == '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $action == 'new-account' && !$this->filtersNewAccounts() ) {
|
||||
if ( $action === 'new-account' && !$this->filtersNewAccounts() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $this->mParams['antispoof'] ) && is_callable( 'AntiSpoof::checkUnicodeString' ) ) {
|
||||
list( $ok, $norm ) = AntiSpoof::checkUnicodeString( $title );
|
||||
if ( $ok == "OK" ) {
|
||||
if ( isset( $this->mParams['antispoof'] )
|
||||
&& is_callable( 'AntiSpoof::checkUnicodeString' )
|
||||
) {
|
||||
if ( $action === 'edit' ) {
|
||||
// Use process cache for frequently edited pages
|
||||
$cache = ObjectCache::getMainWANInstance();
|
||||
list( $ok, $norm ) = $cache->getWithSetCallback(
|
||||
$cache->makeKey( 'titleblacklist', 'normalized-unicode', md5( $title ) ),
|
||||
$cache::TTL_MONTH,
|
||||
function () use ( $title ) {
|
||||
return AntiSpoof::checkUnicodeString( $title );
|
||||
}
|
||||
);
|
||||
} else {
|
||||
list( $ok, $norm ) = AntiSpoof::checkUnicodeString( $title );
|
||||
}
|
||||
|
||||
if ( $ok === "OK" ) {
|
||||
list( $ver, $title ) = explode( ':', $norm, 2 );
|
||||
} else {
|
||||
wfDebugLog( 'TitleBlacklist', 'AntiSpoof could not normalize "' . $title . '".' );
|
||||
|
@ -384,7 +398,10 @@ class TitleBlacklistEntry {
|
|||
}
|
||||
|
||||
wfSuppressWarnings();
|
||||
$match = preg_match( "/^(?:{$this->mRegex})$/us" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), $title );
|
||||
$match = preg_match(
|
||||
"/^(?:{$this->mRegex})$/us" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ),
|
||||
$title
|
||||
);
|
||||
wfRestoreWarnings();
|
||||
|
||||
if ( $match ) {
|
||||
|
@ -403,6 +420,7 @@ class TitleBlacklistEntry {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue