r86154 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86153‎ | r86154 | r86155 >
Date:23:20, 15 April 2011
Author:aaron
Status:ok
Tags:
Comment:
* Replaced parser cache functions in FlaggedRevs.class with new FRParserCacheStable class; duplication reduced
* Renamed updateCacheTracking -> updateStableOnlyDeps and moved some functions to be together
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FRParserCacheStable.php (added) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -255,6 +255,7 @@
256256 $wgAutoloadClasses['FRInclusionManager'] = $accessDir . 'FRInclusionManager.php';
257257 $wgAutoloadClasses['FlaggedPage'] = $accessDir . 'FlaggedPage.php';
258258 $wgAutoloadClasses['FlaggedRevision'] = $accessDir . 'FlaggedRevision.php';
 259+$wgAutoloadClasses['FRParserCacheStable'] = $accessDir . 'FRParserCacheStable.php';
259260
260261 # Event handler classes...
261262 $wgAutoloadClasses['FlaggedRevsHooks'] = $dir . 'FlaggedRevs.hooks.php';
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
@@ -575,112 +575,6 @@
576576 return $parserOut;
577577 }
578578
579 - /**
580 - * Like ParserCache::getKey() with stable-pcache instead of pcache
581 - */
582 - protected static function getCacheKey( ParserCache $parserCache, Article $article, $popts ) {
583 - $key = $parserCache->getKey( $article, $popts );
584 - $key = str_replace( ':pcache:', ':stable-pcache:', $key );
585 - return $key;
586 - }
587 -
588 - /**
589 - * Get the page cache for the stable version of an article
590 - * @param Article $article
591 - * @param ParserOptions $opts
592 - * @return mixed (ParserOutput/false)
593 - */
594 - public static function getPageCache( Article $article, ParserOptions $popts ) {
595 - global $parserMemc, $wgCacheEpoch;
596 - wfProfileIn( __METHOD__ );
597 - # Make sure it is valid
598 - if ( !$article->getId() ) {
599 - wfProfileOut( __METHOD__ );
600 - return null;
601 - }
602 - $parserCache = ParserCache::singleton();
603 - $key = self::getCacheKey( $parserCache, $article, $popts );
604 - # Get the cached HTML
605 - wfDebug( "Trying parser cache $key\n" );
606 - $value = $parserMemc->get( $key );
607 - if ( is_object( $value ) ) {
608 - wfDebug( "Found.\n" );
609 - # Delete if article has changed since the cache was made
610 - $canCache = $article->checkTouched();
611 - $cacheTime = $value->getCacheTime();
612 - $touched = $article->mTouched;
613 - if ( !$canCache || $value->expired( $touched ) ) {
614 - if ( !$canCache ) {
615 - wfIncrStats( "pcache_miss_invalid" );
616 - wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
617 - } else {
618 - wfIncrStats( "pcache_miss_expired" );
619 - wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
620 - }
621 - $parserMemc->delete( $key );
622 - $value = false;
623 - } else {
624 - wfIncrStats( "pcache_hit" );
625 - }
626 - } else {
627 - wfDebug( "Parser cache miss.\n" );
628 - wfIncrStats( "pcache_miss_absent" );
629 - $value = false;
630 - }
631 - wfProfileOut( __METHOD__ );
632 - return $value;
633 - }
634 -
635 - /**
636 - * @param Article $article
637 - * @param ParserOptions $popts
638 - * @param parserOutput $parserOut
639 - * Updates the stable cache of a page with the given $parserOut
640 - */
641 - public static function setPageCache(
642 - Article $article, ParserOptions $popts, ParserOutput $parserOut = null
643 - ) {
644 - global $parserMemc, $wgParserCacheExpireTime, $wgEnableParserCache;
645 - wfProfileIn( __METHOD__ );
646 - # Make sure it is valid and $wgEnableParserCache is enabled
647 - if ( !$wgEnableParserCache || !$parserOut ) {
648 - wfProfileOut( __METHOD__ );
649 - return false;
650 - }
651 - $parserCache = ParserCache::singleton();
652 - $key = self::getCacheKey( $parserCache, $article, $popts );
653 - # Add cache mark to HTML
654 - $now = wfTimestampNow();
655 - $parserOut->setCacheTime( $now );
656 - # Save the timestamp so that we don't have to load the revision row on view
657 - $parserOut->mTimestamp = $article->getTimestamp();
658 - $parserOut->mText .= "\n<!-- Saved in stable version parser cache with key $key and timestamp $now -->";
659 - # Set expire time
660 - if ( $parserOut->containsOldMagic() ) {
661 - $expire = 3600; // 1 hour
662 - } else {
663 - $expire = $wgParserCacheExpireTime;
664 - }
665 - # Save to objectcache
666 - $parserMemc->set( $key, $parserOut, $expire );
667 - wfProfileOut( __METHOD__ );
668 - return true;
669 - }
670 -
671 - /**
672 - * @param Article $article
673 - * @param parserOutput $parserOut
674 - * Updates the stable-only cache dependency table
675 - */
676 - public static function updateCacheTracking( Article $article, ParserOutput $stableOut ) {
677 - wfProfileIn( __METHOD__ );
678 - if ( !wfReadOnly() ) {
679 - $frDepUpdate = new FRDependencyUpdate( $article->getTitle(), $stableOut );
680 - $frDepUpdate->doUpdate();
681 - }
682 - wfProfileOut( __METHOD__ );
683 - }
684 -
685579 # ################ Tracking/cache update update functions #################
686580
687581 /**
@@ -728,6 +622,40 @@
729623 }
730624
731625 /**
 626+ * Clear FlaggedRevs tracking tables for this page
 627+ * @param int|array $pageId (int or array)
 628+ */
 629+ public static function clearTrackingRows( $pageId ) {
 630+ $dbw = wfGetDB( DB_MASTER );
 631+ $dbw->delete( 'flaggedpages', array( 'fp_page_id' => $pageId ), __METHOD__ );
 632+ $dbw->delete( 'flaggedrevs_tracking', array( 'ftr_from' => $pageId ), __METHOD__ );
 633+ $dbw->delete( 'flaggedpage_pending', array( 'fpp_page_id' => $pageId ), __METHOD__ );
 634+ }
 635+
 636+ /**
 637+ * @param Article $article
 638+ * @param parserOutput $parserOut
 639+ * Updates the stable-only cache dependency table
 640+ */
 641+ public static function updateStableOnlyDeps( Article $article, ParserOutput $stableOut ) {
 642+ wfProfileIn( __METHOD__ );
 643+ if ( !wfReadOnly() ) {
 644+ $frDepUpdate = new FRDependencyUpdate( $article->getTitle(), $stableOut );
 645+ $frDepUpdate->doUpdate();
 646+ }
 647+ wfProfileOut( __METHOD__ );
 648+ }
 649+
 650+ /**
 651+ * Clear tracking table of stable-only links for this page
 652+ * @param int|array $pageId (int or array)
 653+ */
 654+ public static function clearStableOnlyDeps( $pageId ) {
 655+ $dbw = wfGetDB( DB_MASTER );
 656+ $dbw->delete( 'flaggedrevs_tracking', array( 'ftr_from' => $pageId ), __METHOD__ );
 657+ }
 658+
 659+ /**
732660 * @param Title $title
733661 * Updates squid cache for a title. Defers till after main commit().
734662 */
@@ -959,26 +887,6 @@
960888 return ( in_array( $ns, $namespaces ) );
961889 }
962890
963 - /**
964 - * Clear FlaggedRevs tracking tables for this page
965 - * @param int|array $pageId (int or array)
966 - */
967 - public static function clearTrackingRows( $pageId ) {
968 - $dbw = wfGetDB( DB_MASTER );
969 - $dbw->delete( 'flaggedpages', array( 'fp_page_id' => $pageId ), __METHOD__ );
970 - $dbw->delete( 'flaggedrevs_tracking', array( 'ftr_from' => $pageId ), __METHOD__ );
971 - $dbw->delete( 'flaggedpage_pending', array( 'fpp_page_id' => $pageId ), __METHOD__ );
972 - }
973 -
974 - /**
975 - * Clear tracking table of stable-only links for this page
976 - * @param int|array $pageId (int or array)
977 - */
978 - public static function clearStableOnlyDeps( $pageId ) {
979 - $dbw = wfGetDB( DB_MASTER );
980 - $dbw->delete( 'flaggedrevs_tracking', array( 'ftr_from' => $pageId ), __METHOD__ );
981 - }
982 -
983891 # ################ Auto-review function #################
984892
985893 /**
Index: trunk/extensions/FlaggedRevs/dataclasses/FRParserCacheStable.php
@@ -0,0 +1,40 @@
 2+<?php
 3+/**
 4+ * Cache for stable version outputs of the PHP parser
 5+ */
 6+class FRParserCacheStable extends ParserCache {
 7+ /**
 8+ * Get an instance of this object
 9+ */
 10+ public static function singleton() {
 11+ static $instance;
 12+ if ( !isset( $instance ) ) {
 13+ global $parserMemc;
 14+ $instance = new FRParserCacheStable( $parserMemc );
 15+ }
 16+ return $instance;
 17+ }
 18+
 19+ /**
 20+ * Like ParserCache::getParserOutputKey() with stable-pcache instead of pcache
 21+ * @param $article Article
 22+ * @param $hash
 23+ * @return mixed|string
 24+ */
 25+ protected function getParserOutputKey( $article, $hash ) {
 26+ $key = parent::getParserOutputKey( $article, $hash ); // call super!
 27+ $key = str_replace( ':pcache:', ':stable-pcache:', $key );
 28+ return $key;
 29+ }
 30+
 31+ /**
 32+ * Like ParserCache::getOptionsKey() with stable-pcache instead of pcache
 33+ * @param $article Article
 34+ * @return mixed|string
 35+ */
 36+ protected function getOptionsKey( $article ) {
 37+ $key = parent::getOptionsKey( $article ); // call super!
 38+ $key = str_replace( ':pcache:', ':stable-pcache:', $key );
 39+ return $key;
 40+ }
 41+}
Property changes on: trunk/extensions/FlaggedRevs/dataclasses/FRParserCacheStable.php
___________________________________________________________________
Added: svn:eol-style
142 + native
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
@@ -672,7 +672,8 @@
673673
674674 # Get parsed stable version and output HTML
675675 $parserOptions = $this->article->makeParserOptions( $wgUser );
676 - $parserOut = FlaggedRevs::getPageCache( $this->article, $parserOptions );
 676+ $parserCache = FRParserCacheStable::singleton();
 677+ $parserOut = $parserCache->get( $this->article, $parserOptions );
677678 if ( $parserOut ) {
678679 $this->addParserOutput( $parserOut );
679680 } else {
@@ -685,12 +686,12 @@
686687 $parserOut = FlaggedRevs::parseStableText(
687688 $this->article->getTitle(), $text, $srev->getRevId(), $parserOptions );
688689 # Update the stable version cache
689 - FlaggedRevs::setPageCache( $this->article, $parserOptions, $parserOut );
 690+ $parserCache->save( $parserOut, $this->article, $parserOptions );
690691 # Add the stable output to the page view
691692 $this->addParserOutput( $parserOut );
692693
693694 # Update the stable version dependancies
694 - FlaggedRevs::updateCacheTracking( $this->article, $parserOut );
 695+ FlaggedRevs::updateStableOnlyDeps( $this->article, $parserOut );
695696 } else {
696697 $wgOut->addHtml( $redirHtml );
697698 }

Status & tagging log