From: Aaron Schulz Date: Thu, 6 Apr 2017 00:25:45 +0000 (-0700) Subject: Reduce contention during view-based category count refreshes X-Git-Tag: 1.31.0-rc.0~3586^2 X-Git-Url: http://git.cyclocoop.org/clavettes/images/Dun%D0%B0?a=commitdiff_plain;h=922e68f739f143;p=lhc%2Fweb%2Fwiklou.git Reduce contention during view-based category count refreshes Bug: T162121 Change-Id: I05b539922508d5e73979ccc8ea1c148b16dd13db --- diff --git a/includes/CategoryViewer.php b/includes/CategoryViewer.php index 31369b0187..0205d708ca 100644 --- a/includes/CategoryViewer.php +++ b/includes/CategoryViewer.php @@ -742,7 +742,13 @@ class CategoryViewer extends ContextSource { $totalcnt = $rescnt; $category = $this->cat; DeferredUpdates::addCallableUpdate( function () use ( $category ) { - $category->refreshCounts(); + # Avoid excess contention on the same category (T162121) + $dbw = wfGetDB( DB_MASTER ); + $name = __METHOD__ . ':' . md5( $this->mName ); + $scopedLock = $dbw->getScopedLockAndFlush( $name, __METHOD__, 1 ); + if ( $scopedLock ) { + $category->refreshCounts(); + } } ); } else { // Case 3: hopeless. Don't give a total count at all.