MessageCache: Avoid 'contributions' replicas
[lhc/web/wiklou.git] / includes / cache / MessageCache.php
index 355aff4..8f88ee9 100644 (file)
@@ -193,6 +193,7 @@ class MessageCache {
                                $po = ParserOptions::newFromAnon();
                                $po->setEditSection( false );
                                $po->setAllowUnsafeRawHtml( false );
+                               $po->setWrapOutputClass( false );
                                return $po;
                        }
 
@@ -202,6 +203,11 @@ class MessageCache {
                        // from malicious sources. As a precaution, disable
                        // the <html> parser tag when parsing messages.
                        $this->mParserOptions->setAllowUnsafeRawHtml( false );
+                       // Wrapping messages in an extra <div> is probably not expected. If
+                       // they're outside the content area they probably shouldn't be
+                       // targeted by CSS that's targeting the parser output, and if
+                       // they're inside they already are from the outer div.
+                       $this->mParserOptions->setWrapOutputClass( false );
                }
 
                return $this->mParserOptions;
@@ -458,7 +464,11 @@ class MessageCache {
        protected function loadFromDB( $code, $mode = null ) {
                global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
 
-               $dbr = wfGetDB( ( $mode == self::FOR_UPDATE ) ? DB_MASTER : DB_REPLICA );
+               // (T164666) The query here performs really poorly on WMF's
+               // contributions replicas. We don't have a way to say "any group except
+               // contributions", so for the moment let's specify 'api'.
+               // @todo: Get rid of this hack.
+               $dbr = wfGetDB( ( $mode == self::FOR_UPDATE ) ? DB_MASTER : DB_REPLICA, 'api' );
 
                $cache = [];
 
@@ -509,15 +519,18 @@ class MessageCache {
 
                # Conditions to load the remaining pages with their contents
                $smallConds = $conds;
-               $smallConds[] = 'page_latest=rev_id';
-               $smallConds[] = 'rev_text_id=old_id';
                $smallConds[] = 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize );
 
                $res = $dbr->select(
                        [ 'page', 'revision', 'text' ],
                        [ 'page_title', 'old_id', 'old_text', 'old_flags' ],
                        $smallConds,
-                       __METHOD__ . "($code)-small"
+                       __METHOD__ . "($code)-small",
+                       [],
+                       [
+                               'revision' => [ 'JOIN', 'page_latest=rev_id' ],
+                               'text' => [ 'JOIN', 'rev_text_id=old_id' ],
+                       ]
                );
 
                foreach ( $res as $row ) {