Merge "API DB commit and sticky DC cookie fixes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 23 Nov 2015 00:43:59 +0000 (00:43 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 23 Nov 2015 00:43:59 +0000 (00:43 +0000)
includes/MediaWiki.php
includes/api/ApiMain.php

index d5aac07..38d9e47 100644 (file)
@@ -486,13 +486,22 @@ class MediaWiki {
                $this->doPostOutputShutdown( 'normal' );
        }
 
+       /**
+        * @see MediaWiki::preOutputCommit()
+        * @since 1.26
+        */
+       public function doPreOutputCommit() {
+               self::preOutputCommit( $this->context );
+       }
+
        /**
         * This function commits all DB changes as needed before
         * the user can receive a response (in case commit fails)
         *
-        * @since 1.26
+        * @param IContextSource $context
+        * @since 1.27
         */
-       public function doPreOutputCommit() {
+       public static function preOutputCommit( IContextSource $context ) {
                // Either all DBs should commit or none
                ignore_user_abort( true );
 
@@ -505,16 +514,17 @@ class MediaWiki {
 
                // Set a cookie to tell all CDN edge nodes to "stick" the user to the
                // DC that handles this POST request (e.g. the "master" data center)
-               $request = $this->context->getRequest();
+               $request = $context->getRequest();
+               $config = $context->getConfig();
                if ( $request->wasPosted() && $factory->hasOrMadeRecentMasterChanges() ) {
-                       $expires = time() + $this->config->get( 'DataCenterUpdateStickTTL' );
-                       $request->response()->setCookie( 'UseDC', 'master', $expires );
+                       $expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
+                       $request->response()->setCookie( 'UseDC', 'master', $expires, array( 'prefix' => '' ) );
                }
 
                // Avoid letting a few seconds of slave lag cause a month of stale data
                if ( $factory->laggedSlaveUsed() ) {
-                       $maxAge = $this->config->get( 'CdnMaxageLagged' );
-                       $this->context->getOutput()->lowerCdnMaxage( $maxAge );
+                       $maxAge = $config->get( 'CdnMaxageLagged' );
+                       $context->getOutput()->lowerCdnMaxage( $maxAge );
                        $request->response()->header( "X-Database-Lagged: true" );
                        wfDebugLog( 'replication', "Lagged DB used; CDN cache TTL limited to $maxAge seconds" );
                }
index ca5e1bb..0d1314f 100644 (file)
@@ -434,6 +434,9 @@ class ApiMain extends ApiBase {
                // Log the request whether or not there was an error
                $this->logRequest( microtime( true ) - $t );
 
+               // Commit DBs and send any related cookies and headers
+               MediaWiki::preOutputCommit( $this->getContext() );
+
                // Send cache headers after any code which might generate an error, to
                // avoid sending public cache headers for errors.
                $this->sendCacheHeaders( $isError );