Move countVisitingWatchers to WatchedItemStore
[lhc/web/wiklou.git] / includes / WatchedItemStore.php
index 86e4925..c59beec 100644 (file)
@@ -205,6 +205,35 @@ class WatchedItemStore {
                return $return;
        }
 
+       /**
+        * Number of page watchers who also visited a "recent" edit
+        *
+        * @param LinkTarget $target
+        * @param mixed $threshold timestamp accepted by wfTimestamp
+        *
+        * @return int
+        * @throws DBUnexpectedError
+        * @throws MWException
+        */
+       public function countVisitingWatchers( LinkTarget $target, $threshold ) {
+               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 'watchlist' ] );
+               $visitingWatchers = (int)$dbr->selectField(
+                       'watchlist',
+                       'COUNT(*)',
+                       [
+                               'wl_namespace' => $target->getNamespace(),
+                               'wl_title' => $target->getDBkey(),
+                               'wl_notificationtimestamp >= ' .
+                               $dbr->addQuotes( $dbr->timestamp( $threshold ) ) .
+                               ' OR wl_notificationtimestamp IS NULL'
+                       ],
+                       __METHOD__
+               );
+               $this->loadBalancer->reuseConnection( $dbr );
+
+               return $visitingWatchers;
+       }
+
        /**
         * @param LinkTarget[] $targets
         * @param array $options Allowed keys: