X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWatchedItemQueryService.php;h=d0f45bec171016779236eab031affa3742365d61;hb=29990dadc71c25a5cd0fbf52d798b543a4964ac9;hp=22d5439c06ebf959af430466b52163379bed980b;hpb=2dd58ade75d15a5895c0c010e17b6f729a0f72fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchedItemQueryService.php b/includes/WatchedItemQueryService.php index 22d5439c06..d0f45bec17 100644 --- a/includes/WatchedItemQueryService.php +++ b/includes/WatchedItemQueryService.php @@ -55,6 +55,10 @@ class WatchedItemQueryService { /** @var WatchedItemQueryServiceExtension[]|null */ private $extensions = null; + /** + * @var CommentStore|null */ + private $commentStore = null; + public function __construct( LoadBalancer $loadBalancer ) { $this->loadBalancer = $loadBalancer; } @@ -78,6 +82,13 @@ class WatchedItemQueryService { 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: @@ -172,13 +183,9 @@ class WatchedItemQueryService { ); } - $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 ); @@ -313,13 +320,24 @@ class WatchedItemQueryService { $allFields = get_object_vars( $row ); $rcKeys = array_filter( array_keys( $allFields ), - function( $key ) { + function ( $key ) { return substr( $key, 0, 3 ) === 'rc_'; } ); 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', @@ -355,7 +373,7 @@ class WatchedItemQueryService { $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' ] ); @@ -657,6 +675,9 @@ class WatchedItemQueryService { 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; }