http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88821
Revision: 88821
Author: aaron
Date: 2011-05-25 19:38:24 +0000 (Wed, 25 May 2011)
Log Message:
-----------
* Follow-up r88740:
* Moved getRevIncludes() process only to where it's needed for simplicity
* Tweaked getRevIncludes() cache check to try the rev's author's parser options
* Lengthened getRevIncludes() cache time but made it double-check page_latest
* Added cachePendingRevs.php script to rebuild the caches for pending revs
Modified Paths:
--------------
trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
Added Paths:
-----------
trunk/extensions/FlaggedRevs/maintenance/cachePendingRevs.php
Modified: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
===================================================================
--- trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
2011-05-25 19:35:38 UTC (rev 88820)
+++ trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
2011-05-25 19:38:24 UTC (rev 88821)
@@ -581,30 +581,33 @@
* @param Article $article
* @param Revision $rev
* @param User $user
+ * @param string $regen use 'regen' to force regeneration
* @return array( templateIds, fileSHA1Keys )
* templateIds like ParserOutput->mTemplateIds
* fileSHA1Keys like ParserOutput->mImageTimeKeys
*/
- public static function getRevIncludes( Article $article, Revision $rev,
User $user ) {
+ public static function getRevIncludes(
+ Article $article, Revision $rev, User $user, $regen = ''
+ ) {
global $wgParser, $wgMemc;
- static $versionCache = array();
wfProfileIn( __METHOD__ );
+ $versions = false;
$hash = md5( $article->getTitle()->getPrefixedDBkey() );
# Check process cache first...
- $vKey = $rev->getId()."-$hash";
- if ( isset( $versionCache[$vKey] ) ) {
- wfProfileOut( __METHOD__ );
- return $versionCache[$vKey]; // hit
+ $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $rev->getId(),
$hash );
+ if ( $regen !== 'regen' ) {
+ $versions = FlaggedRevs::getMemcValue( $wgMemc->get(
$key ), $article, 'allowStale' );
}
- $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $rev->getId(),
$hash );
- $val = FlaggedRevs::getMemcValue( $wgMemc->get( $key ),
$article );
- if ( is_array( $val ) ) {
- $versions = $val; // cache hit
- } else {
+ if ( !is_array( $versions ) ) { // cache miss
$pOut = false;
- if ( $rev->isCurrent() ) { // try current version
parser cache
+ if ( $rev->isCurrent() ) {
$parserCache = ParserCache::singleton();
+ # Try current version parser cache (as anon)...
$pOut = $parserCache->get( $article,
$article->makeParserOptions( $user ) );
+ if ( $pOut == false && $rev->getUser() ) { //
try the user who saved the change
+ $author = User::newFromId(
$rev->getUser() );
+ $pOut = $parserCache->get( $article,
$article->makeParserOptions( $author ) );
+ }
}
if ( $pOut == false ) {
$title = $article->getTitle();
@@ -620,13 +623,25 @@
$versions = array( $pOut->getTemplateIds(),
$pOut->getImageTimeKeys() );
# Save to cache...
$data = FlaggedRevs::makeMemcObj( $versions );
- $wgMemc->set( $key, $data, 3600 ); // inclusions may be
dynamic
- }
- # Save to process cache...
- if ( count( $versionCache ) > 100 ) {
- $versionCache = array(); // sanity
- }
- $versionCache[$vKey] = $versions;
+ $wgMemc->set( $key, $data, 24*3600 ); // inclusions may
be dynamic
+ } else {
+ # Do a link batch query for page_latest...
+ $lb = new LinkBatch();
+ foreach ( $versions as $ns => $tmps ) {
+ foreach ( $tmps as $dbKey => $revIdDraft ) {
+ $lb->add( $ns, $dbKey );
+ }
+ }
+ $lb->execute();
+ # Update array with the current page_latest values.
+ # This kludge is there since $newTemplates (thus
$revIdDraft) is cached.
+ foreach ( $versions as $ns => $tmps ) {
+ foreach ( $tmps as $dbKey => &$revIdDraft ) {
+ $title = new Title( $ns, $dbKey );
+ $revIdDraft =
(int)$title->getLatestRevID();
+ }
+ }
+ }
wfProfileOut( __METHOD__ );
return $versions;
}
Modified: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
===================================================================
--- trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
2011-05-25 19:35:38 UTC (rev 88820)
+++ trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
2011-05-25 19:38:24 UTC (rev 88821)
@@ -714,9 +714,9 @@
# ################ Other utility functions #################
/**
+ * Get a memcache storage object
* @param string $val
* @return Object (val,time) tuple
- * Get a memcache storage object
*/
public static function makeMemcObj( $val ) {
$data = (object) array();
@@ -726,14 +726,17 @@
}
/**
+ * Return memc value if not expired
* @param object|false $data makeMemcObj() tuple
* @param Article $article
+ * @param $allowStale Use 'allowStale' to skip page_touched check
* @return mixed
- * Return memc value if not expired
*/
- public static function getMemcValue( $data, Article $article ) {
- if ( is_object( $data ) && $data->time >=
$article->getTouched() ) {
- return $data->value;
+ public static function getMemcValue( $data, Article $article,
$allowStale = '' ) {
+ if ( is_object( $data ) ) {
+ if ( $allowStale === 'allowStale' || $data->time >=
$article->getTouched() ) {
+ return $data->value;
+ }
}
return false;
}
Added: trunk/extensions/FlaggedRevs/maintenance/cachePendingRevs.php
===================================================================
--- trunk/extensions/FlaggedRevs/maintenance/cachePendingRevs.php
(rev 0)
+++ trunk/extensions/FlaggedRevs/maintenance/cachePendingRevs.php
2011-05-25 19:38:24 UTC (rev 88821)
@@ -0,0 +1,59 @@
+<?php
+/**
+ * This script precaches parser output related data of pending revs
+ *
+ * @ingroup Maintenance
+ */
+
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+ $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+ $IP = dirname(__FILE__).'/../../..';
+}
+
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class CachePendingRevs extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Cache pending revision data";
+ }
+
+ public function execute() {
+ global $wgUser;
+ $dbr = wfGetDB( DB_SLAVE );
+ $ret = $dbr->select(
+ array( 'flaggedpages', 'revision', 'page' ),
+ array_merge( Revision::selectFields(), array(
$dbr->tableName( 'page' ) . '.*' ) ),
+ array( 'fp_pending_since IS NOT NULL',
+ 'page_id = fp_page_id',
+ 'rev_page = fp_page_id',
+ 'rev_timestamp >= fp_pending_since'
+ ),
+ __METHOD__
+ );
+ foreach ( $ret as $row ) {
+ $title = Title::newFromRow( $row );
+ $article = new Article( $title );
+ $rev = new Revision( $row );
+ // Trigger cache regeneration
+ $start = microtime( true );
+ RevisionReviewForm::getRevIncludes( $article, $rev,
$wgUser, 'regen' );
+ $elapsed = intval( ( microtime( true ) - $start ) *
1000 );
+ $this->cachePendingRevsLog(
+ $title->getPrefixedDBkey() . " rev:" .
$rev->getId() . " {$elapsed}ms" );
+ }
+ }
+
+ /**
+ * Log the cache message
+ * @param $msg String The message to log
+ */
+ private function cachePendingRevsLog( $msg ) {
+ $this->output( wfTimestamp( TS_DB ) . " $msg\n" );
+ wfDebugLog( 'cachePendingRevs', $msg );
+ }
+}
+
+$maintClass = "CachePendingRevs";
+require_once( RUN_MAINTENANCE_IF_MAIN );
Property changes on:
trunk/extensions/FlaggedRevs/maintenance/cachePendingRevs.php
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
===================================================================
--- trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
2011-05-25 19:35:38 UTC (rev 88820)
+++ trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
2011-05-25 19:38:24 UTC (rev 88821)
@@ -7,6 +7,7 @@
protected $article = null;
protected $diffRevs = null; // assoc array of old and new Revisions for
diffs
+ protected $oldRevIncludes = null; // ( array of templates, array of
file)
protected $isReviewableDiff = false;
protected $isDiffFromStable = false;
protected $isMultiPageDiff = false;
@@ -1082,6 +1083,8 @@
# RevisionReviewForm will fetch them as needed however.
if ( $this->out->getRevisionId() == $rev->getId() ) {
$form->setIncludeVersions(
$this->out->getTemplateIds(), $this->out->getImageTimeKeys() );
+ } elseif ( $this->oldRevIncludes ) {
+ $form->setIncludeVersions(
$this->oldRevIncludes[0], $this->oldRevIncludes[1] );
}
list( $html, $status ) = $form->getHtml();
# Diff action: place the form at the top of the page
@@ -1372,6 +1375,7 @@
$changeList = self::fetchTemplateChanges(
$srev, $incs[0] );
# Add a list of links to each changed file...
$changeList = array_merge( $changeList,
self::fetchFileChanges( $srev, $incs[1] ) );
+ $this->oldRevIncludes = $incs; // process cache
}
# If there are pending revs or templates/files changes,
notify the user...
if ( $this->article->revsArePending() || count(
$changeList ) ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs