Merge "resourceloader: Fix duplicate semi-colon in generated startup code"
[lhc/web/wiklou.git] / includes / Category.php
index ac5cc42..41ecc65 100644 (file)
@@ -48,7 +48,7 @@ class Category {
 
        /**
         * Set up all member variables using a database query.
-        * @param int $mode
+        * @param int $mode One of (Category::LOAD_ONLY, Category::LAZY_INIT_ROW)
         * @throws MWException
         * @return bool True on success, false on failure.
         */
@@ -328,13 +328,23 @@ class Category {
                $dbw = wfGetDB( DB_MASTER );
                # Avoid excess contention on the same category (T162121)
                $name = __METHOD__ . ':' . md5( $this->mName );
-               $scopedLock = $dbw->getScopedLockAndFlush( $name, __METHOD__, 1 );
+               $scopedLock = $dbw->getScopedLockAndFlush( $name, __METHOD__, 0 );
                if ( !$scopedLock ) {
                        return false;
                }
 
                $dbw->startAtomic( __METHOD__ );
 
+               // Lock the `category` row before locking `categorylinks` rows to try
+               // to avoid deadlocks with LinksDeletionUpdate (T195397)
+               $dbw->selectField(
+                       'category',
+                       1,
+                       [ 'cat_title' => $this->mName ],
+                       __METHOD__,
+                       [ 'FOR UPDATE' ]
+               );
+
                // Lock all the `categorylinks` records and gaps for this category;
                // this is a separate query due to postgres/oracle limitations
                $dbw->selectRowCount(