X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2FMediaWiki.php;h=0f40c1920180286cbd829f13fdcf09be15a8e1c2;hb=8a463e8ea5c73b7ac8ee70e6ca07ba89cce2c0a9;hp=4e471844d88b8164326134f0912fa960a2f6ed77;hpb=6c9a2923fe1ee3a65cb027be5e781772f2b12fbd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 4e471844d8..0f40c19201 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -607,7 +607,7 @@ class MediaWiki { $request->wasPosted() && $output->getRedirect() && $lbFactory->hasOrMadeRecentMasterChanges( INF ) - ) ? self::getUrlDomainDistance( $output->getRedirect(), $context ) : false; + ) ? self::getUrlDomainDistance( $output->getRedirect() ) : false; $allowHeaders = !( $output->isDisabled() || headers_sent() ); if ( $urlDomainDistance === 'local' || $urlDomainDistance === 'remote' ) { @@ -676,34 +676,14 @@ class MediaWiki { /** * @param string $url - * @param IContextSource $context * @return string Either "local", "remote" if in the farm, "external" otherwise */ - private static function getUrlDomainDistance( $url, IContextSource $context ) { - static $relevantKeys = [ 'host' => true, 'port' => true ]; - - $infoCandidate = wfParseUrl( $url ); - if ( $infoCandidate === false ) { - return 'external'; - } - - $infoCandidate = array_intersect_key( $infoCandidate, $relevantKeys ); - $clusterHosts = array_merge( - // Local wiki host (the most common case) - [ $context->getConfig()->get( 'CanonicalServer' ) ], - // Any local/remote wiki virtual hosts for this wiki farm - $context->getConfig()->get( 'LocalVirtualHosts' ) - ); - - foreach ( $clusterHosts as $i => $clusterHost ) { - $parseUrl = wfParseUrl( $clusterHost ); - if ( !$parseUrl ) { - continue; - } - $infoHost = array_intersect_key( $parseUrl, $relevantKeys ); - if ( $infoCandidate === $infoHost ) { - return ( $i === 0 ) ? 'local' : 'remote'; - } + private static function getUrlDomainDistance( $url ) { + $clusterWiki = WikiMap::getWikiFromUrl( $url ); + if ( $clusterWiki === wfWikiID() ) { + return 'local'; // the current wiki + } elseif ( $clusterWiki !== false ) { + return 'remote'; // another wiki in this cluster/farm } return 'external'; @@ -732,10 +712,11 @@ class MediaWiki { MWExceptionHandler::rollbackMasterChangesAndLog( $e ); } + $blocksHttpClient = true; // Defer everything else if possible... - $callback = function () use ( $mode ) { + $callback = function () use ( $mode, &$blocksHttpClient ) { try { - $this->restInPeace( $mode ); + $this->restInPeace( $mode, $blocksHttpClient ); } catch ( Exception $e ) { // If this is post-send, then displaying errors can cause broken HTML MWExceptionHandler::rollbackMasterChangesAndLog( $e ); @@ -745,9 +726,11 @@ class MediaWiki { if ( function_exists( 'register_postsend_function' ) ) { // https://github.com/facebook/hhvm/issues/1230 register_postsend_function( $callback ); + $blocksHttpClient = false; } else { if ( function_exists( 'fastcgi_finish_request' ) ) { fastcgi_finish_request(); + $blocksHttpClient = false; } else { // Either all DB and deferred updates should happen or none. // The latter should not be cancelled due to client disconnect. @@ -890,8 +873,9 @@ class MediaWiki { /** * Ends this task peacefully * @param string $mode Use 'fast' to always skip job running + * @param bool $blocksHttpClient Whether this blocks an HTTP response to a client */ - public function restInPeace( $mode = 'fast' ) { + public function restInPeace( $mode = 'fast', $blocksHttpClient = true ) { $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); // Assure deferred updates are not in the main transaction $lbFactory->commitMasterChanges( __METHOD__ ); @@ -907,8 +891,8 @@ class MediaWiki { // Important: this must be the last deferred update added (T100085, T154425) DeferredUpdates::addCallableUpdate( [ JobQueueGroup::class, 'pushLazyJobs' ] ); - // Do any deferred jobs - DeferredUpdates::doUpdates( 'enqueue' ); + // Do any deferred jobs; preferring to run them now if a client will not wait on them + DeferredUpdates::doUpdates( $blocksHttpClient ? 'enqueue' : 'run' ); // Now that everything specific to this request is done, // try to occasionally run jobs (if enabled) from the queues @@ -970,7 +954,7 @@ class MediaWiki { } /** - * @param integer $n Number of jobs to try to run + * @param int $n Number of jobs to try to run * @param LoggerInterface $runJobsLogger */ private function triggerSyncJobs( $n, LoggerInterface $runJobsLogger ) { @@ -979,7 +963,7 @@ class MediaWiki { } /** - * @param integer $n Number of jobs to try to run + * @param int $n Number of jobs to try to run * @param LoggerInterface $runJobsLogger * @return bool Success */