Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / watcheditem / WatchedItemQueryService.php
index a85e7e8..6094f41 100644 (file)
@@ -65,14 +65,19 @@ class WatchedItemQueryService {
        /** @var ActorMigration */
        private $actorMigration;
 
+       /** @var WatchedItemStoreInterface */
+       private $watchedItemStore;
+
        public function __construct(
                LoadBalancer $loadBalancer,
                CommentStore $commentStore,
-               ActorMigration $actorMigration
+               ActorMigration $actorMigration,
+               WatchedItemStoreInterface $watchedItemStore
        ) {
                $this->loadBalancer = $loadBalancer;
                $this->commentStore = $commentStore;
                $this->actorMigration = $actorMigration;
+               $this->watchedItemStore = $watchedItemStore;
        }
 
        /**
@@ -228,11 +233,14 @@ class WatchedItemQueryService {
                                break;
                        }
 
+                       $target = new TitleValue( (int)$row->rc_namespace, $row->rc_title );
                        $items[] = [
                                new WatchedItem(
                                        $user,
-                                       new TitleValue( (int)$row->rc_namespace, $row->rc_title ),
-                                       $row->wl_notificationtimestamp
+                                       $target,
+                                       $this->watchedItemStore->getLatestNotificationTimestamp(
+                                               $row->wl_notificationtimestamp, $user, $target
+                                       )
                                ),
                                $this->getRecentChangeFieldsFromRow( $row )
                        ];
@@ -307,11 +315,14 @@ class WatchedItemQueryService {
 
                $watchedItems = [];
                foreach ( $res as $row ) {
+                       $target = new TitleValue( (int)$row->wl_namespace, $row->wl_title );
                        // todo these could all be cached at some point?
                        $watchedItems[] = new WatchedItem(
                                $user,
-                               new TitleValue( (int)$row->wl_namespace, $row->wl_title ),
-                               $row->wl_notificationtimestamp
+                               $target,
+                               $this->watchedItemStore->getLatestNotificationTimestamp(
+                                       $row->wl_notificationtimestamp, $user, $target
+                               )
                        );
                }
 
@@ -434,11 +445,9 @@ class WatchedItemQueryService {
 
                $conds = array_merge( $conds, $this->getStartEndConds( $db, $options ) );
 
-               if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
-                       if ( $db->getType() === 'mysql' ) {
-                               // This is an index optimization for mysql
-                               $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
-                       }
+               if ( !isset( $options['start'] ) && !isset( $options['end'] ) && $db->getType() === 'mysql' ) {
+                       // This is an index optimization for mysql
+                       $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
                }
 
                $conds = array_merge( $conds, $this->getUserRelatedConds( $db, $user, $options ) );
@@ -693,7 +702,7 @@ class WatchedItemQueryService {
 
        private function getWatchedItemsWithRCInfoQueryJoinConds( array $options ) {
                $joinConds = [
-                       'watchlist' => [ 'INNER JOIN',
+                       'watchlist' => [ 'JOIN',
                                [
                                        'wl_namespace=rc_namespace',
                                        'wl_title=rc_title'