From: Aaron Schulz Date: Wed, 18 Apr 2018 23:09:55 +0000 (-0700) Subject: Avoid locking aggregated SELECT in Category::refresh X-Git-Tag: 1.34.0-rc.0~5635^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=3fc98b9c6ba6a8298eec77f4f2b8f9bad0890196;p=lhc%2Fweb%2Fwiklou.git Avoid locking aggregated SELECT in Category::refresh LOCK IN SHARE MODE is not allowed with aggregation on postgres/oracle. Split out the locking and aggregation into two separate queries. Change-Id: I7f8d113fb678b368437dad84bdb93e81db314cd5 --- diff --git a/includes/Category.php b/includes/Category.php index 9241730a04..ac5cc42e35 100644 --- a/includes/Category.php +++ b/includes/Category.php @@ -335,18 +335,28 @@ class Category { $dbw->startAtomic( __METHOD__ ); - $cond1 = $dbw->conditional( [ 'page_namespace' => NS_CATEGORY ], 1, 'NULL' ); - $cond2 = $dbw->conditional( [ 'page_namespace' => NS_FILE ], 1, 'NULL' ); - $result = $dbw->selectRow( + // Lock all the `categorylinks` records and gaps for this category; + // this is a separate query due to postgres/oracle limitations + $dbw->selectRowCount( [ 'categorylinks', 'page' ], - [ 'pages' => 'COUNT(*)', - 'subcats' => "COUNT($cond1)", - 'files' => "COUNT($cond2)" - ], + '*', [ 'cl_to' => $this->mName, 'page_id = cl_from' ], __METHOD__, [ 'LOCK IN SHARE MODE' ] ); + // Get the aggregate `categorylinks` row counts for this category + $catCond = $dbw->conditional( [ 'page_namespace' => NS_CATEGORY ], 1, 'NULL' ); + $fileCond = $dbw->conditional( [ 'page_namespace' => NS_FILE ], 1, 'NULL' ); + $result = $dbw->selectRow( + [ 'categorylinks', 'page' ], + [ + 'pages' => 'COUNT(*)', + 'subcats' => "COUNT($catCond)", + 'files' => "COUNT($fileCond)" + ], + [ 'cl_to' => $this->mName, 'page_id = cl_from' ], + __METHOD__ + ); $shouldExist = $result->pages > 0 || $this->getTitle()->exists();