Aaron Schulz has uploaded a new change for review.

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

Change subject: [WIP] Use pool counter for page parses
......................................................................

[WIP] Use pool counter for page parses

Bug: T95750
Change-Id: Ie2ca0e6ba73c87ae25503cc63dc3a6de7abe8d8b
---
M backend/FlaggedRevs.class.php
M frontend/FlaggablePageView.php
2 files changed, 68 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlaggedRevs 
refs/changes/67/208367/1

diff --git a/backend/FlaggedRevs.class.php b/backend/FlaggedRevs.class.php
old mode 100644
new mode 100755
index ff4c010..510abfc
--- a/backend/FlaggedRevs.class.php
+++ b/backend/FlaggedRevs.class.php
@@ -520,6 +520,46 @@
        # ################ Parsing functions #################
 
        /**
+        * Get the HTML output of a revision, using PoolCounter in the process
+        *
+        * Returns a Status if pool is full, null if the revision is missing
+        *
+        * @param FlaggedRevision $frev
+        * @param ParserOptions $pOpts
+        * @return ParserOutput|Status|null
+        */
+       public static function parseStableRevisionPooled(
+               FlaggedRevision $frev, ParserOptions $pOpts
+       ) {
+               $page = WikiPage::factory( $frev->getTitle() );
+               $keyPrefix = FRParserCacheStable::singleton()->getKey( $page, 
$pOpts );
+               $keyPrefix = $keyPrefix ?: wfMemcKey( 'articleview', 
'missingcachekey' );
+
+               $work = new PoolCounterWorkViaCallback(
+                       'ArticleView', // use standard parse PoolCounter config
+                       $keyPrefix . ':revid:' . $frev->getRevId(),
+                       array(
+                               'doWork' => function () use ( $frev, $pOpts ) {
+                                       return 
FlaggedRevs::parseStableRevision( $frev, $pOpts );
+                               },
+                               'doCachedWork' => function () use ( $page, 
$pOpts ) {
+                                       // Use new cache value from other thread
+                                       return 
FRParserCacheStable::singleton()->get( $page, $pOpts );
+                               },
+                               'fallback' => function () use ( $page, $pOpts ) 
{
+                                       // Use stale cache if possible
+                                       return 
FRParserCacheStable::singleton()->getDirty( $page, $pOpts );
+                               },
+                               'error' => function ( Status $status ) {
+                                       return $status;
+                               },
+                       )
+               );
+
+               return $work->execute();
+       }
+
+       /**
         * Get the HTML output of a revision.
         * @param FlaggedRevision $frev
         * @param ParserOptions $pOpts
diff --git a/frontend/FlaggablePageView.php b/frontend/FlaggablePageView.php
index 85364db..863e0d8 100755
--- a/frontend/FlaggablePageView.php
+++ b/frontend/FlaggablePageView.php
@@ -681,23 +681,25 @@
                        # Cache hit. Note that redirects are not cached.
                        $this->out->addParserOutput( $parserOut );
                } else {
+                       $parserOut = false;
                        # Get the new stable parser output...
                        if ( FlaggedRevs::inclusionSetting() == 
FR_INCLUDES_CURRENT && $synced ) {
                                # We can try the current version cache, since 
they are the same revision
                                $parserOut = ParserCache::singleton()->get( 
$this->article, $pOpts );
-                       } else {
-                               $parserOut = false;
                        }
 
                        if ( !$parserOut ) {
-                               $parserOut = FlaggedRevs::parseStableRevision( 
$srev, $pOpts );
+                               # Actually parse the revision from source text
+                               $parserOut = 
FlaggedRevs::parseStableRevisionPooled( $srev, $pOpts );
                        }
 
-                       if ( !$parserOut ) { // serious error
-                               $this->out->addWikiMsg( 'missing-article',
-                                       
$this->article->getTitle()->getPrefixedText(),
-                                       $this->msg( 'missingarticle-rev', 
$srev->getRevId() )->text()
-                               );
+                       if ( $parserOut instanceof Status ) {
+                               $this->showPoolError( $parserOut );
+
+                               return null;
+                       } elseif ( !( $parserOut instanceof ParserOutput ) ) { 
// serious error
+                               $this->showMissingRevError( $srev->getRevId() );
+
                                return null;
                        }
 
@@ -721,6 +723,24 @@
                return $parserOut;
        }
 
+       protected function showPoolError( Status $status ) {
+               $this->out->enableClientCache( false );
+               $this->out->setRobotPolicy('noindex,nofollow' );
+
+               $errortext = $status->getWikiText( false, 'view-pool-error' );
+               $this->out->addWikiText( '<div class="errorbox">' . $errortext 
. '</div>' );
+       }
+
+       protected function showMissingRevError( $revId ) {
+               $this->out->enableClientCache( false );
+               $this->out->setRobotPolicy( 'noindex,nofollow' );
+
+               $this->out->addWikiMsg( 'missing-article',
+                       $this->article->getTitle()->getPrefixedText(),
+                       $this->msg( 'missingarticle-rev', $revId )->text()
+               );
+       }
+
        // Show icons for draft/stable/old reviewed versions
        protected function showRatingIcon() {
                if ( FlaggedRevs::useOnlyIfProtected() ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2ca0e6ba73c87ae25503cc63dc3a6de7abe8d8b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlaggedRevs
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

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

Reply via email to