jenkins-bot has submitted this change and it was merged.

Change subject: WatchedItemStore add db connection helper methods
......................................................................


WatchedItemStore add db connection helper methods

As suggested in:
https://gerrit.wikimedia.org/r/#/c/277276/2/includes/WatchedItemStore.php

Change-Id: Id82d987eee025e21efc381bd441cd07fbc50aea0
---
M includes/WatchedItemStore.php
1 file changed, 37 insertions(+), 18 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 11eb60c..ff3ae21 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -207,12 +207,31 @@
        }
 
        /**
+        * @param int $slaveOrMaster DB_MASTER or DB_SLAVE
+        *
+        * @return DatabaseBase
+        * @throws MWException
+        */
+       private function getConnection( $slaveOrMaster ) {
+               return $this->loadBalancer->getConnection( $slaveOrMaster, [ 
'watchlist' ] );
+       }
+
+       /**
+        * @param DatabaseBase $connection
+        *
+        * @throws MWException
+        */
+       private function reuseConnection( $connection ) {
+               $this->loadBalancer->reuseConnection( $connection );
+       }
+
+       /**
         * @param LinkTarget $target
         *
         * @return int
         */
        public function countWatchers( LinkTarget $target ) {
-               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 
'watchlist' ] );
+               $dbr = $this->getConnection( DB_SLAVE );
                $return = (int)$dbr->selectField(
                        'watchlist',
                        'COUNT(*)',
@@ -222,7 +241,7 @@
                        ],
                        __METHOD__
                );
-               $this->loadBalancer->reuseConnection( $dbr );
+               $this->reuseConnection( $dbr );
 
                return $return;
        }
@@ -238,7 +257,7 @@
         * @throws MWException
         */
        public function countVisitingWatchers( LinkTarget $target, $threshold ) 
{
-               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 
'watchlist' ] );
+               $dbr = $this->getConnection( DB_SLAVE );
                $visitingWatchers = (int)$dbr->selectField(
                        'watchlist',
                        'COUNT(*)',
@@ -251,7 +270,7 @@
                        ],
                        __METHOD__
                );
-               $this->loadBalancer->reuseConnection( $dbr );
+               $this->reuseConnection( $dbr );
 
                return $visitingWatchers;
        }
@@ -268,7 +287,7 @@
        public function countWatchersMultiple( array $targets, array $options = 
[] ) {
                $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
 
-               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 
'watchlist' ] );
+               $dbr = $this->getConnection( DB_SLAVE );
 
                if ( array_key_exists( 'minimumWatchers', $options ) ) {
                        $dbOptions['HAVING'] = 'COUNT(*) >= ' . 
(int)$options['minimumWatchers'];
@@ -283,7 +302,7 @@
                        $dbOptions
                );
 
-               $this->loadBalancer->reuseConnection( $dbr );
+               $this->reuseConnection( $dbr );
 
                $watchCounts = [];
                foreach ( $targets as $linkTarget ) {
@@ -331,14 +350,14 @@
                        return false;
                }
 
-               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 
'watchlist' ] );
+               $dbr = $this->getConnection( DB_SLAVE );
                $row = $dbr->selectRow(
                        'watchlist',
                        'wl_notificationtimestamp',
                        $this->dbCond( $user, $target ),
                        __METHOD__
                );
-               $this->loadBalancer->reuseConnection( $dbr );
+               $this->reuseConnection( $dbr );
 
                if ( !$row ) {
                        return false;
@@ -410,13 +429,13 @@
                        return false;
                }
 
-               $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 
'watchlist' ] );
+               $dbw = $this->getConnection( DB_MASTER );
                foreach ( array_chunk( $rows, 100 ) as $toInsert ) {
                        // Use INSERT IGNORE to avoid overwriting the 
notification timestamp
                        // if there's already an entry for this page
                        $dbw->insert( 'watchlist', $toInsert, __METHOD__, 
'IGNORE' );
                }
-               $this->loadBalancer->reuseConnection( $dbw );
+               $this->reuseConnection( $dbw );
 
                return true;
        }
@@ -440,7 +459,7 @@
 
                $this->uncache( $user, $target );
 
-               $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 
'watchlist' ] );
+               $dbw = $this->getConnection( DB_MASTER );
                $dbw->delete( 'watchlist',
                        [
                                'wl_user' => $user->getId(),
@@ -449,7 +468,7 @@
                        ], __METHOD__
                );
                $success = (bool)$dbw->affectedRows();
-               $this->loadBalancer->reuseConnection( $dbw );
+               $this->reuseConnection( $dbw );
 
                return $success;
        }
@@ -463,7 +482,7 @@
         * @return int[] Array of user IDs the timestamp has been updated for
         */
        public function updateNotificationTimestamp( User $editor, LinkTarget 
$target, $timestamp ) {
-               $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 
'watchlist' ] );
+               $dbw = $this->getConnection( DB_MASTER );
                $res = $dbw->select( [ 'watchlist' ],
                        [ 'wl_user' ],
                        [
@@ -498,7 +517,7 @@
                        );
                }
 
-               $this->loadBalancer->reuseConnection( $dbw );
+               $this->reuseConnection( $dbw );
 
                return $watchers;
        }
@@ -615,7 +634,7 @@
                        $queryOptions['LIMIT'] = $unreadLimit;
                }
 
-               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 
'watchlist' ] );
+               $dbr = $this->getConnection( DB_SLAVE );
                $rowCount = $dbr->selectRowCount(
                        'watchlist',
                        '1',
@@ -626,7 +645,7 @@
                        __METHOD__,
                        $queryOptions
                );
-               $this->loadBalancer->reuseConnection( $dbr );
+               $this->reuseConnection( $dbr );
 
                if ( !isset( $unreadLimit ) ) {
                        return $rowCount;
@@ -671,7 +690,7 @@
         * @param LinkTarget $newTarget
         */
        public function duplicateEntry( LinkTarget $oldTarget, LinkTarget 
$newTarget ) {
-               $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 
'watchlist' ] );
+               $dbw = $this->getConnection( DB_MASTER );
 
                $result = $dbw->select(
                        'watchlist',
@@ -710,7 +729,7 @@
                        );
                }
 
-               $this->loadBalancer->reuseConnection( $dbw );
+               $this->reuseConnection( $dbw );
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/277520
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id82d987eee025e21efc381bd441cd07fbc50aea0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to