aboutsummaryrefslogtreecommitdiffstats
path: root/includes/WatchedItemStore.php
diff options
context:
space:
mode:
authorLeszek Manicki <leszek.manicki@wikimedia.de>2016-03-18 14:43:26 +0100
committerLeszek Manicki <leszek.manicki@wikimedia.de>2016-03-21 10:25:54 +0100
commitb92ae1501e0a3a7e3eaa0cf513f9b76de2cebb38 (patch)
treee0e760526d595b99fd9085abfc000681388adf1f /includes/WatchedItemStore.php
parentb915320928fbdad844d062785e96e31bdddbb4eb (diff)
downloadmediawikicore-b92ae1501e0a3a7e3eaa0cf513f9b76de2cebb38.tar.gz
mediawikicore-b92ae1501e0a3a7e3eaa0cf513f9b76de2cebb38.zip
Use WatchedItemStore in ApiQueryInfo::getWatchedInfo
Adds a method for getting watchlist's notification timestamps for a batch of LinkTargets. Bug: T129482 Change-Id: I1f84212e7879a84b34bb3b53859069fcea282bba
Diffstat (limited to 'includes/WatchedItemStore.php')
-rw-r--r--includes/WatchedItemStore.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 4e2dfa5d995d..8a3f205103b4 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -503,6 +503,61 @@ class WatchedItemStore {
}
/**
+ * @param User $user
+ * @param LinkTarget[] $targets
+ *
+ * @return array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp,
+ * where $timestamp is:
+ * - string|null value of wl_notificationtimestamp,
+ * - false if $target is not watched by $user.
+ */
+ public function getNotificationTimestampsBatch( User $user, array $targets ) {
+ $timestamps = [];
+ foreach ( $targets as $target ) {
+ $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
+ }
+
+ if ( $user->isAnon() ) {
+ return $timestamps;
+ }
+
+ $targetsToLoad = [];
+ foreach ( $targets as $target ) {
+ $cachedItem = $this->getCached( $user, $target );
+ if ( $cachedItem ) {
+ $timestamps[$target->getNamespace()][$target->getDBkey()] =
+ $cachedItem->getNotificationTimestamp();
+ } else {
+ $targetsToLoad[] = $target;
+ }
+ }
+
+ if ( !$targetsToLoad ) {
+ return $timestamps;
+ }
+
+ $dbr = $this->getConnection( DB_SLAVE );
+
+ $lb = new LinkBatch( $targetsToLoad );
+ $res = $dbr->select(
+ 'watchlist',
+ [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
+ [
+ $lb->constructSet( 'wl', $dbr ),
+ 'wl_user' => $user->getId(),
+ ],
+ __METHOD__
+ );
+ $this->reuseConnection( $dbr );
+
+ foreach ( $res as $row ) {
+ $timestamps[(int)$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
+ }
+
+ return $timestamps;
+ }
+
+ /**
* Must be called separately for Subject & Talk namespaces
*
* @param User $user