Pass database connection to SpecialWatchlist::countItems
authorumherirrender <umherirrender_de.wp@web.de>
Sun, 13 Jan 2013 19:21:27 +0000 (20:21 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Sun, 13 Jan 2013 19:21:27 +0000 (20:21 +0100)
This avoids getting two connection to the 'watchlist' group.

Change-Id: I36cefc7d54cb6ed6c58a6f16932809b72a573d98

includes/specials/SpecialWatchlist.php

index 3cfa31f..029cc29 100644 (file)
@@ -91,7 +91,9 @@ class SpecialWatchlist extends SpecialPage {
                        return;
                }
 
-               $nitems = $this->countItems();
+               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
+
+               $nitems = $this->countItems( $dbr );
                if ( $nitems == 0 ) {
                        $output->addWikiMsg( 'nowatchlist' );
                        return;
@@ -190,8 +192,6 @@ class SpecialWatchlist extends SpecialPage {
                        return;
                }
 
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
                # Possible where conditions
                $conds = array();
 
@@ -497,11 +497,10 @@ class SpecialWatchlist extends SpecialPage {
        /**
         * Count the number of items on a user's watchlist
         *
+        * @param $dbr A database connection
         * @return Integer
         */
-       protected function countItems() {
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
+       protected function countItems( $dbr ) {
                # Fetch the raw count
                $res = $dbr->select( 'watchlist', array( 'count' => 'COUNT(*)' ),
                        array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ );