Reduce contention during view-based category count refreshes

Bug: T162121
Change-Id: I05b539922508d5e73979ccc8ea1c148b16dd13db
This commit is contained in:
Aaron Schulz 2017-04-05 17:25:45 -07:00
parent 040f2961bc
commit 922e68f739

View file

@ -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.