← All changes
|
json-endpoints/class.wpcom-json-api-list-comments-endpoint.php
+13
-4
16.2
→
16.3-beta
View file →
| @@ -317,12 +317,8 @@ | ||
| 317 | 317 | $query['date_query']['after'] = $args['after_gmt']; |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | - if ( $args['hierarchical'] && $found > 5000 ) { | |
| 322 | - // Massive comment thread found; don't pre-load comment metadata to reduce memory used. | |
| 323 | - $query['update_comment_meta_cache'] = false; | |
| 324 | - } | |
| 325 | 321 | |
| 326 | 322 | if ( $post_id ) { |
| 327 | 323 | $post = get_post( $post_id ); |
| 328 | 324 | if ( ! $post || is_wp_error( $post ) ) { |
| @@ -337,8 +333,21 @@ | ||
| 337 | 333 | if ( ! $comment || is_wp_error( $comment ) ) { |
| 338 | 334 | return new WP_Error( 'unknown_comment', 'Unknown comment', 404 ); |
| 339 | 335 | } |
| 340 | 336 | $query['parent'] = $comment_id; |
| 337 | + } | |
| 338 | + | |
| 339 | + // A single post's count uses the comment_post_ID index; site-wide typed counts would not. | |
| 340 | + if ( -1 === $found && $post_id ) { | |
| 341 | + $count_query = $query; | |
| 342 | + $count_query['count'] = true; | |
| 343 | + unset( $count_query['number'], $count_query['offset'] ); | |
| 344 | + $found = (int) get_comments( $count_query ); | |
| 345 | + } | |
| 346 | + | |
| 347 | + if ( $args['hierarchical'] && $found > 5000 ) { | |
| 348 | + // Massive comment thread found; don't pre-load comment metadata to reduce memory used. | |
| 349 | + $query['update_comment_meta_cache'] = false; | |
| 341 | 350 | } |
| 342 | 351 | |
| 343 | 352 | $comments = get_comments( $query ); |
| 344 | 353 | |