Unsuppress phan issues part 6
[lhc/web/wiklou.git] / includes / Revision / RevisionRenderer.php
index 99150c1..ea90255 100644 (file)
@@ -95,6 +95,7 @@ class RevisionRenderer {
         *        matched the $rev and $options. This mechanism is intended as a temporary stop-gap,
         *        for the time until caches have been changed to store RenderedRevision states instead
         *        of ParserOutput objects.
+        * @phan-param array{use-master?:bool,audience?:int,known-revision-output?:ParserOutput} $hints
         *
         * @return RenderedRevision|null The rendered revision, or null if the audience checks fails.
         */
@@ -108,6 +109,7 @@ class RevisionRenderer {
                        throw new InvalidArgumentException( 'Mismatching wiki ID ' . $rev->getWikiId() );
                }
 
+               // @phan-suppress-next-line PhanTypeInvalidDimOffset
                $audience = $hints['audience']
                        ?? ( $forUser ? RevisionRecord::FOR_THIS_USER : RevisionRecord::FOR_PUBLIC );
 
@@ -121,6 +123,7 @@ class RevisionRenderer {
                        $options = ParserOptions::newCanonical( $forUser ?: 'canonical' );
                }
 
+               // @phan-suppress-next-line PhanTypeInvalidDimOffset
                $useMaster = $hints['use-master'] ?? false;
 
                $dbIndex = $useMaster
@@ -130,6 +133,9 @@ class RevisionRenderer {
                $options->setSpeculativeRevIdCallback( function () use ( $dbIndex ) {
                        return $this->getSpeculativeRevId( $dbIndex );
                } );
+               $options->setSpeculativePageIdCallback( function () use ( $dbIndex ) {
+                       return $this->getSpeculativePageId( $dbIndex );
+               } );
 
                if ( !$rev->getId() && $rev->getTimestamp() ) {
                        // This is an unsaved revision with an already determined timestamp.
@@ -161,12 +167,9 @@ class RevisionRenderer {
        }
 
        private function getSpeculativeRevId( $dbIndex ) {
-               // Use a fresh master connection in order to see the latest data, by avoiding
+               // Use a separate master connection in order to see the latest data, by avoiding
                // stale data from REPEATABLE-READ snapshots.
-               // HACK: But don't use a fresh connection in unit tests, since it would not have
-               // the fake tables. This should be handled by the LoadBalancer!
-               $flags = defined( 'MW_PHPUNIT_TEST' ) || $dbIndex === DB_REPLICA
-                       ? 0 : ILoadBalancer::CONN_TRX_AUTOCOMMIT;
+               $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
 
                $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
 
@@ -178,6 +181,21 @@ class RevisionRenderer {
                );
        }
 
+       private function getSpeculativePageId( $dbIndex ) {
+               // Use a separate master connection in order to see the latest data, by avoiding
+               // stale data from REPEATABLE-READ snapshots.
+               $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
+
+               $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
+
+               return 1 + (int)$db->selectField(
+                       'page',
+                       'MAX(page_id)',
+                       [],
+                       __METHOD__
+               );
+       }
+
        /**
         * This implements the layout for combining the output of multiple slots.
         *