Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/289325
Change subject: Use caching in TitleBlacklist::matches() for existing pages
......................................................................
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
---
M TitleBlacklist.list.php
1 file changed, 28 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TitleBlacklist
refs/changes/25/289325/1
diff --git a/TitleBlacklist.list.php b/TitleBlacklist.list.php
index 9772679..9f99366 100755
--- a/TitleBlacklist.list.php
+++ b/TitleBlacklist.list.php
@@ -357,26 +357,40 @@
}
/**
- * 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 @@
}
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 @@
}
return true;
}
+
return false;
}
--
To view, visit https://gerrit.wikimedia.org/r/289325
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebbe6a90020d756e800ebf7b9b12d39b86190a48
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits