jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



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: merged
Gerrit-Change-Id: Iebbe6a90020d756e800ebf7b9b12d39b86190a48
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to