/** @var WatchedItemQueryServiceExtension[]|null */
private $extensions = null;
+ /**
+ * @var CommentStore|null */
+ private $commentStore = null;
+
public function __construct( LoadBalancer $loadBalancer ) {
$this->loadBalancer = $loadBalancer;
}
return $this->loadBalancer->getConnectionRef( DB_REPLICA, [ 'watchlist' ] );
}
+ private function getCommentStore() {
+ if ( !$this->commentStore ) {
+ $this->commentStore = new CommentStore( 'rc_comment' );
+ }
+ return $this->commentStore;
+ }
+
/**
* @param User $user
* @param array $options Allowed keys:
);
}
- $tables = [ 'recentchanges', 'watchlist' ];
- if ( !$options['allRevisions'] ) {
- $tables[] = 'page';
- }
-
$db = $this->getConnection();
+ $tables = $this->getWatchedItemsWithRCInfoQueryTables( $options );
$fields = $this->getWatchedItemsWithRCInfoQueryFields( $options );
$conds = $this->getWatchedItemsWithRCInfoQueryConds( $db, $user, $options );
$dbOptions = $this->getWatchedItemsWithRCInfoQueryDbOptions( $options );
return array_intersect_key( $allFields, array_flip( $rcKeys ) );
}
+ private function getWatchedItemsWithRCInfoQueryTables( array $options ) {
+ $tables = [ 'recentchanges', 'watchlist' ];
+ if ( !$options['allRevisions'] ) {
+ $tables[] = 'page';
+ }
+ if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) {
+ $tables += $this->getCommentStore()->getJoin()['tables'];
+ }
+ return $tables;
+ }
+
private function getWatchedItemsWithRCInfoQueryFields( array $options ) {
$fields = [
'rc_id',
$fields[] = 'rc_user';
}
if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) {
- $fields[] = 'rc_comment';
+ $fields += $this->getCommentStore()->getJoin()['fields'];
}
if ( in_array( self::INCLUDE_PATROL_INFO, $options['includeFields'] ) ) {
$fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] );
if ( !$options['allRevisions'] ) {
$joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
}
+ if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) {
+ $joinConds += $this->getCommentStore()->getJoin()['joins'];
+ }
return $joinConds;
}