Mattflaschen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322214

Change subject: populateContentModel: Invalidate content model and revision 
cache
......................................................................

populateContentModel: Invalidate content model and revision cache

The cache is computed from both the default values and the DB.

If someone visits the page when the wrong default value is there,
it will be cached.

When we populate the DB with the correct value (usually in preparation
for changing the namespace default), we need to invalidate the
potentially broken cache.

Change-Id: I995c0d9fdec529a456762571d5406d0bd0d33aed
---
M maintenance/populateContentModel.php
1 file changed, 40 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/14/322214/1

diff --git a/maintenance/populateContentModel.php 
b/maintenance/populateContentModel.php
index c6bd794..95e7a63 100644
--- a/maintenance/populateContentModel.php
+++ b/maintenance/populateContentModel.php
@@ -28,6 +28,10 @@
  *  populateContentModel.php --ns=1 --table=page
  */
 class PopulateContentModel extends Maintenance {
+       protected $wikiId;
+
+       protected $wanCache;
+
        public function __construct() {
                parent::__construct();
                $this->addDescription( 'Populate the various content_* fields' 
);
@@ -38,6 +42,11 @@
 
        public function execute() {
                $dbw = $this->getDB( DB_MASTER );
+
+               $this->wikiId = $dbw->getWikiID();
+
+               $this->wanCache = ObjectCache::getMainWANInstance();
+
                $ns = $this->getOption( 'ns' );
                if ( !ctype_digit( $ns ) && $ns !== 'all' ) {
                        $this->error( 'Invalid namespace', 1 );
@@ -55,6 +64,17 @@
                        default:
                                $this->error( "Invalid table name: $table", 1 );
                }
+       }
+
+       protected function clearCache( $page_id, $rev_id ) {
+               $contentModelKey = $this->wanCache->makeKey( 'page', 
'content-model', $rev_id );
+               $revisionKey = $this->wanCache->makeGlobalKey( 'revision', 
$this->wikiId, $page_id, $rev_id );
+
+               // WikiPage content model cache
+               $this->wanCache->delete( $contentModelKey );
+
+               // Revision object cache, which contains a content model
+               $this->wanCache->delete( $revisionKey );
        }
 
        private function updatePageRows( Database $dbw, $pageIds, $model ) {
@@ -117,6 +137,7 @@
                        [ $key => $ids ],
                        __METHOD__
                );
+
                $this->output( "done.\n" );
        }
 
@@ -130,19 +151,24 @@
                        $fields = [ 'ar_namespace', 'ar_title' ];
                        $join_conds = [];
                        $where = $ns === 'all' ? [] : [ 'ar_namespace' => $ns ];
+                       $page_id_column = 'ar_page_id';
+                       $rev_id_column = 'ar_rev_id';
                } else { // revision
                        $selectTables = [ 'revision', 'page' ];
                        $fields = [ 'page_title', 'page_namespace' ];
                        $join_conds = [ 'page' => [ 'INNER JOIN', 
'rev_page=page_id' ] ];
                        $where = $ns === 'all' ? [] : [ 'page_namespace' => $ns 
];
+                       $page_id_column = 'rev_page';
+                       $rev_id_column = 'rev_id';
                }
 
                $toSave = [];
+               $idsToClear = [];
                $lastId = 0;
                do {
                        $rows = $dbw->select(
                                $selectTables,
-                               array_merge( $fields, [ $model_column, 
$format_column, $key ] ),
+                               array_merge( $fields, [ $model_column, 
$format_column, $key, $page_id_column, $rev_id_column ] ),
                                // @todo support populating format if model is 
already set
                                [
                                        $model_column => null,
@@ -174,9 +200,17 @@
                                if ( $dbModel === null && $dbFormat === null ) {
                                        // Set the defaults
                                        $toSave[$defaultModel][] = $row->{$key};
+                                       $idsToClear[] = [
+                                               'page_id' => 
$row->{$page_id_column},
+                                               'rev_id' => 
$row->{$rev_id_column},
+                                       ];
                                } else { // $dbModel === null, $dbFormat set.
                                        if ( $dbFormat === $defaultFormat ) {
                                                $toSave[$defaultModel][] = 
$row->{$key};
+                                               $idsToClear[] = [
+                                                       'page_id' => 
$row->{$page_id_column},
+                                                       'rev_id' => 
$row->{$rev_id_column},
+                                               ];
                                        } else { // non-default format, just 
update now
                                                $this->output( "Updating model 
to match format for $table $id of $title... " );
                                                $dbw->update(
@@ -186,6 +220,7 @@
                                                        __METHOD__
                                                );
                                                wfWaitForSlaves();
+                                               $this->clearCache( 
$row->{$page_id_column}, $row->{$rev_id_column} );
                                                $this->output( "done.\n" );
                                                continue;
                                        }
@@ -200,6 +235,10 @@
                foreach ( $toSave as $model => $ids ) {
                        $this->updateRevisionOrArchiveRows( $dbw, $ids, $model, 
$table );
                }
+
+               foreach ( $idsToClear as $idPair ) {
+                       $this->clearCache( $idPair['page_id'], 
$idPair['rev_id'] );
+               }
        }
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I995c0d9fdec529a456762571d5406d0bd0d33aed
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to