Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/190409
Change subject: Removed doCascadeProtectionUpdates method to avoid DB writes on
page views
......................................................................
Removed doCascadeProtectionUpdates method to avoid DB writes on page views
* Use special prioritized refreshLinksJobs instead
Change-Id: I8e5a6ddb643c12e0fb5c1c68bc83f912944e6e8d
---
M includes/DefaultSettings.php
M includes/jobqueue/jobs/RefreshLinksJob.php
M includes/page/WikiPage.php
M includes/poolcounter/PoolWorkArticleView.php
4 files changed, 63 insertions(+), 71 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/09/190409/1
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index d4cdf9e..bddccec 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6422,6 +6422,7 @@
'PublishStashedFile' => 'PublishStashedFileJob',
'ThumbnailRender' => 'ThumbnailRenderJob',
'recentChangesUpdate' => 'RecentChangesUpdateJob',
+ 'refreshLinksPrioritized' => 'RefreshLinksJob', // for cascading
protection
'null' => 'NullJob'
);
diff --git a/includes/jobqueue/jobs/RefreshLinksJob.php
b/includes/jobqueue/jobs/RefreshLinksJob.php
index 5d95792..bafdd40 100644
--- a/includes/jobqueue/jobs/RefreshLinksJob.php
+++ b/includes/jobqueue/jobs/RefreshLinksJob.php
@@ -39,6 +39,10 @@
function __construct( $title, $params = '' ) {
parent::__construct( 'refreshLinks', $title, $params );
+ // A separate type is used just for cascade-protected backlinks
+ if ( !empty( $this->params['prioritize'] ) ) {
+ $this->command .= 'Prioritized';
+ }
// Base backlink update jobs and per-title update jobs can be
de-duplicated.
// If template A changes twice before any jobs run, a clean
queue will have:
// (A base, A base)
@@ -85,6 +89,16 @@
1, // job-per-title
array( 'params' => $extraParams )
);
+ // Get jobs for cascade-protected backlinks for a high
priority queue.
+ // If meta-templates change to using a new template,
the new template
+ // should be implicitly protected as soon as possible,
if applicable.
+ // These jobs duplicate a subset of the above ones, but
can run sooner.
+ // Which ever runs first generally no-ops the other one.
+ foreach ( $this->getCascadeProtectedBacklinks(
$this->title ) as $title ) {
+ $jobs[] = new RefreshLinksJob( $title,
+ array( 'prioritize' => true ) +
$extraParams );
+ }
+ // Enqueue all of the sub-jobs
JobQueueGroup::singleton()->push( $jobs );
// Job to update link tables for a set of titles
} elseif ( isset( $this->params['pages'] ) ) {
@@ -100,6 +114,54 @@
return true;
}
+ /**
+ * @return TitleArray
+ */
+ protected function getCascadeProtectedBacklinks( Title $title ) {
+ // This method is used to make redudant jobs anyway, so its OK
to use
+ // a slave. Also, the set of cascade protected pages tends to
be stable.
+ $dbr = wfGetDB( DB_SLAVE );
+
+ //
http://dev.mysql.com/doc/refman/5.6/en/subquery-optimization.html
+ // The use if IN() should allow for various strategies,
appropriate
+ // for both the cases of pages with many and few backlinks.
+ $queries = array();
+ $queries[] = $dbr->selectSQLText(
+ array( 'templatelinks', 'page' ),
+ array( 'page_namespace', 'page_title' ),
+ array(
+ 'tl_namespace' => $title->getNamespace(),
+ 'tl_title' => $title->getDBkey(),
+ 'tl_from IN (' . $dbr->selectSQLText(
+ 'page_restrictions',
+ 'pr_page',
+ array( 'pr_cascade' => 1 ) ) . ')',
+ 'page_id = tl_from'
+ )
+ );
+ $queries[] = $dbr->selectSQLText(
+ array( 'imagelinks', 'page' ),
+ array( 'page_namespace', 'page_title' ),
+ array(
+ 'il_to' => $title->getDBkey(),
+ 'il_from IN (' . $dbr->selectSQLText(
+ 'page_restrictions',
+ 'pr_page',
+ array( 'pr_cascade' => 1 ) ) . ')',
+ 'page_id = il_from'
+ )
+ );
+
+ return TitleArray::newFromResult( $dbr->query(
+ $dbr->unionQueries( $queries, false ),
+ __METHOD__
+ ) );
+ }
+
+ /**
+ * @param Title $title
+ * @return bool
+ */
protected function runForTitle( Title $title = null ) {
$linkCache = LinkCache::singleton();
$linkCache->clear();
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 2f900f9..4d98e3d 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3374,73 +3374,6 @@
}
/**
- * Updates cascading protections
- *
- * @param ParserOutput $parserOutput ParserOutput object for the
current version
- */
- public function doCascadeProtectionUpdates( ParserOutput $parserOutput
) {
- if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading()
) {
- return;
- }
-
- // templatelinks or imagelinks tables may have become out of
sync,
- // especially if using variable-based transclusions.
- // For paranoia, check if things have changed and if
- // so apply updates to the database. This will ensure
- // that cascaded protections apply as soon as the changes
- // are visible.
-
- // Get templates from templatelinks and images from imagelinks
- $id = $this->getId();
-
- $dbLinks = array();
-
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( array( 'templatelinks' ),
- array( 'tl_namespace', 'tl_title' ),
- array( 'tl_from' => $id ),
- __METHOD__
- );
-
- foreach ( $res as $row ) {
- $dbLinks["{$row->tl_namespace}:{$row->tl_title}"] =
true;
- }
-
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( array( 'imagelinks' ),
- array( 'il_to' ),
- array( 'il_from' => $id ),
- __METHOD__
- );
-
- foreach ( $res as $row ) {
- $dbLinks[NS_FILE . ":{$row->il_to}"] = true;
- }
-
- // Get templates and images from parser output.
- $poLinks = array();
- foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
- foreach ( $templates as $dbk => $id ) {
- $poLinks["$ns:$dbk"] = true;
- }
- }
- foreach ( $parserOutput->getImages() as $dbk => $id ) {
- $poLinks[NS_FILE . ":$dbk"] = true;
- }
-
- // Get the diff
- $links_diff = array_diff_key( $poLinks, $dbLinks );
-
- if ( count( $links_diff ) > 0 ) {
- // Whee, link updates time.
- // Note: we are only interested in links here. We don't
need to get
- // other DataUpdate items from the parser output.
- $u = new LinksUpdate( $this->mTitle, $parserOutput,
false );
- $u->doUpdate();
- }
- }
-
- /**
* Return a list of templates used by this article.
* Uses the templatelinks table
*
diff --git a/includes/poolcounter/PoolWorkArticleView.php
b/includes/poolcounter/PoolWorkArticleView.php
index da20f94..24773c5 100644
--- a/includes/poolcounter/PoolWorkArticleView.php
+++ b/includes/poolcounter/PoolWorkArticleView.php
@@ -158,10 +158,6 @@
$wgUseFileCache = false;
}
- if ( $isCurrent ) {
- $this->page->doCascadeProtectionUpdates(
$this->parserOutput );
- }
-
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/190409
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e5a6ddb643c12e0fb5c1c68bc83f912944e6e8d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits