Avoid DBPerformance warnings in Category::initialize()
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 3 Jun 2016 05:07:58 +0000 (22:07 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 3 Jun 2016 22:30:02 +0000 (15:30 -0700)
Use DeferredUpdates and zero-out negative values in the meantime.

Bug: T92357
Change-Id: Ia1339395b70b042edba6dc1d570acb92c90a287b

includes/Category.php

index 6209a1a..28b566a 100644 (file)
@@ -95,7 +95,11 @@ class Category {
                # and should not be kept, and 2) we *probably* don't have to scan many
                # rows to obtain the correct figure, so let's risk a one-time recount.
                if ( $this->mPages < 0 || $this->mSubcats < 0 || $this->mFiles < 0 ) {
-                       $this->refreshCounts();
+                       $this->mPages = max( $this->mPages, 0 );
+                       $this->mSubcats = max( $this->mSubcats, 0 );
+                       $this->mFiles = max( $this->mFiles, 0 );
+
+                       DeferredUpdates::addCallableUpdate( [ $this, 'refreshCounts' ] );
                }
 
                return true;