Reduce deadlocks adding log rows to the RC table on delete
[lhc/web/wiklou.git] / includes / WikiPage.php
index d012d7a..cedbcf9 100644 (file)
@@ -1479,7 +1479,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @throws MWException
         * @return string New complete article text, or null if error.
         *
-        * @deprecated since 1.21, use replaceSectionContent() instead
+        * @deprecated since 1.21, use replaceSectionAtRev() instead
         */
        public function replaceSection( $section, $text, $sectionTitle = '',
                $edittime = null
@@ -1540,13 +1540,9 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $edittime && $section !== 'new' ) {
                        $dbw = wfGetDB( DB_MASTER );
                        $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
-                       if ( !$rev ) {
-                               wfDebug( __METHOD__ . " given bad revision time for page " .
-                                       $this->getId() . "; edittime: $edittime)\n" );
-                               wfProfileOut( __METHOD__ );
-                               return null;
+                       if ( $rev ) {
+                               $baseRevId = $rev->getId();
                        }
-                       $baseRevId = $rev->getId();
                }
 
                wfProfileOut( __METHOD__ );
@@ -1583,13 +1579,13 @@ class WikiPage implements Page, IDBAccessObject {
                        if ( is_null( $baseRevId ) || $section == 'new' ) {
                                $oldContent = $this->getContent();
                        } else {
-                               // TODO: try DB_READ first
+                               // TODO: try DB_SLAVE first
                                $dbw = wfGetDB( DB_MASTER );
                                $rev = Revision::loadFromId( $dbw, $baseRevId );
 
                                if ( !$rev ) {
-                                       wfDebug( "WikiPage::replaceSection asked for bogus section (page: " .
-                                               $this->getId() . "; section: $section; edittime: $edittime)\n" );
+                                       wfDebug( __METHOD__ . " asked for bogus section (page: " .
+                                               $this->getId() . "; section: $section)\n" );
                                        wfProfileOut( __METHOD__ );
                                        return null;
                                }
@@ -1603,7 +1599,6 @@ class WikiPage implements Page, IDBAccessObject {
                                return null;
                        }
 
-                       // FIXME: $oldContent might be null?
                        $newContent = $oldContent->replaceSection( $section, $sectionContent, $sectionTitle );
                }
 
@@ -2879,7 +2874,11 @@ class WikiPage implements Page, IDBAccessObject {
                $logEntry->setTarget( $logTitle );
                $logEntry->setComment( $reason );
                $logid = $logEntry->insert();
-               $logEntry->publish( $logid );
+
+               $dbw->onTransactionPreCommitOrIdle( function() use ( $dbw, $logEntry, $logid ) {
+                       // Bug 56776: avoid deadlocks (especially from FileDeleteForm)
+                       $logEntry->publish( $logid );
+               } );
 
                if ( $commit ) {
                        $dbw->commit( __METHOD__ );