Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/267137
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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter
refs/changes/37/267137/1
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/267137
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I50432658d387b24e47db7ed66880e53c3e4adee7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: wmf/1.27.0-wmf.11
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits