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

Change subject: Compute last-recent-authors result during edit stashing
......................................................................


Compute last-recent-authors result during edit stashing

This query takes a large chunk of page save time (per xenon).
Try to perform the query before page save.

Bug: T116557
Change-Id: I50432658d387b24e47db7ed66880e53c3e4adee7
---
M AbuseFilter.hooks.php
M AbuseFilter.php
M AbuseFilterVariableHolder.php
3 files changed, 55 insertions(+), 18 deletions(-)

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



diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php
index e04ff07..c1dc9bf 100755
--- a/AbuseFilter.hooks.php
+++ b/AbuseFilter.hooks.php
@@ -728,6 +728,19 @@
        }
 
        /**
+        * Warms the cache for getLastPageAuthors() - T116557
+        *
+        * @param WikiPage $page
+        * @param Content $content
+        * @param ParserOutput $output
+        */
+       public static function onParserOutputStashForEdit(
+               WikiPage $page, Content $content, ParserOutput $output
+       ) {
+               AFComputedVariable::getLastPageAuthors( $page->getTitle() );
+       }
+
+       /**
         * Hook to add PHPUnit test cases.
         * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
         *
diff --git a/AbuseFilter.php b/AbuseFilter.php
index 1812ed6..12a8fc6 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -99,6 +99,7 @@
 $wgHooks['ArticleSaveComplete'][] = 'AbuseFilterHooks::onArticleSaveComplete';
 $wgHooks['APIEditBeforeSave'][] = 'AbuseFilterHooks::onAPIEditBeforeSave';
 $wgHooks['UserMergeAccountFields'][] = 
'AbuseFilterHooks::onUserMergeAccountFields';
+$wgHooks['ParserOutputStashForEdit'][] = 
'AbuseFilterHooks::onParserOutputStashForEdit';
 $wgHooks['UnitTestsList'][] = 'AbuseFilterHooks::onUnitTestsList';
 
 $wgAvailableRights[] = 'abusefilter-modify';
diff --git a/AbuseFilterVariableHolder.php b/AbuseFilterVariableHolder.php
index 856ac86..2855dbe 100644
--- a/AbuseFilterVariableHolder.php
+++ b/AbuseFilterVariableHolder.php
@@ -501,25 +501,8 @@
                                        $result = '';
                                        break;
                                }
-                               // Get the last 100 edit authors with a trivial 
query (avoid T116557)
-                               $revAuthors = wfGetDB( DB_SLAVE 
)->selectFieldValues(
-                                       'revision',
-                                       'rev_user_text',
-                                       array( 'rev_page' => 
$title->getArticleID() ),
-                                       __METHOD__,
-                                       // Some pages have < 10 authors but 
many revisions (e.g. bot pages)
-                                       array( 'ORDER BY' => 'rev_timestamp 
DESC', 'LIMIT' => 100 )
-                               );
-                               // Get the last 10 distinct authors within this 
set of edits
-                               $users = array();
-                               foreach ( $revAuthors as $author ) {
-                                       $users[$author] = 1;
-                                       if ( count( $users ) >= 10 ) {
-                                               break;
-                                       }
-                               }
 
-                               $result = array_keys( $users );
+                               $result = self::getLastPageAuthors( $title );
                                break;
                        case 'load-first-author':
                                $title = Title::makeTitle( 
$parameters['namespace'], $parameters['title'] );
@@ -605,4 +588,44 @@
                return $result instanceof AFPData
                        ? $result : AFPData::newFromPHPVar( $result );
        }
+
+       /**
+        * @param Title $title
+        * @return string[] List of the last 10 (unique) authors from $title
+        */
+       public static function getLastPageAuthors( Title $title ) {
+               if ( !$title->exists() ) {
+                       return array();
+               }
+
+               $cache = ObjectCache::getMainWANInstance();
+
+               return $cache->getWithSetCallback(
+                       $cache->makeKey( 'last-10-authors', 'revision', 
$title->getLatestRevID() ),
+                       $cache::TTL_MINUTE,
+                       function ( $oldValue, &$ttl, array &$setOpts ) use ( 
$title ) {
+                               $dbr = wfGetDB( DB_SLAVE );
+                               $setOpts += Database::getCacheSetOptions( $dbr 
);
+                               // Get the last 100 edit authors with a trivial 
query (avoid T116557)
+                               $revAuthors = $dbr->selectFieldValues(
+                                       'revision',
+                                       'rev_user_text',
+                                       array( 'rev_page' => 
$title->getArticleID() ),
+                                       __METHOD__,
+                                       // Some pages have < 10 authors but 
many revisions (e.g. bot pages)
+                                       array( 'ORDER BY' => 'rev_timestamp 
DESC', 'LIMIT' => 100 )
+                               );
+                               // Get the last 10 distinct authors within this 
set of edits
+                               $users = array();
+                               foreach ( $revAuthors as $author ) {
+                                       $users[$author] = 1;
+                                       if ( count( $users ) >= 10 ) {
+                                               break;
+                                       }
+                               }
+
+                               return array_keys( $users );
+                       }
+               );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/266646
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I50432658d387b24e47db7ed66880e53c3e4adee7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Se4598 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to