PluginProbe
WPGraphQL / trunk
WPGraphQL vtrunk
2.22.3 2.22.2 2.22.1 2.22.0 2.21.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.15.0 2.14.1 2.14.0 2.13.0 2.2.0 2.3.0 2.3.3 2.3.6 2.3.8 2.5.0 2.5.1 2.5.2 2.5.3 All 177 releases
wp-graphql / src / Data / Loader / CommentAuthorLoader.php

CommentAuthorLoader.php in WPGraphQL trunk, at src/Data/Loader/CommentAuthorLoader.php

57 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPGraphQL\Data\Loader;
3
4 use WPGraphQL\Model\CommentAuthor;
5
6 /**
7 * Class CommentAuthorLoader
8 *
9 * @package WPGraphQL\Data\Loader
10 */
11 class CommentAuthorLoader extends AbstractDataLoader {
12
13 /**
14 * {@inheritDoc}
15 *
16 * @return ?\WPGraphQL\Model\CommentAuthor
17 */
18 protected function get_model( $entry, $key ) {
19 if ( ! $entry instanceof \WP_Comment ) {
20 return null;
21 }
22
23 return new CommentAuthor( $entry );
24 }
25
26 /**
27 * {@inheritDoc}
28 *
29 * @param int[] $keys Array of IDs to load
30 */
31 public function loadKeys( array $keys ) {
32 /**
33 * Prepare the args for the query. We're provided a specific set of IDs of comments
34 * so we want to query as efficiently as possible with as little overhead to get the comment
35 * objects. No need to count the rows, etc.
36 */
37 $args = [
38 'comment__in' => $keys,
39 'orderby' => 'comment__in',
40 'number' => count( $keys ),
41 'no_found_rows' => true,
42 'count' => false,
43 ];
44
45 /**
46 * Execute the query. Call get_comments() to add them to the cache.
47 */
48 $query = new \WP_Comment_Query( $args );
49 $query->get_comments();
50 $loaded = [];
51 foreach ( $keys as $key ) {
52 $loaded[ $key ] = \WP_Comment::get_instance( $key );
53 }
54 return $loaded;
55 }
56 }
57