Skip to content

Commit 6bc0216

Browse files
committed
Performance improvements
1 parent 54811bd commit 6bc0216

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

Model/Resolver/DataProvider/Post.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public function __construct(
4242

4343
/**
4444
* @param string $postId
45+
* @param array $fields
4546
* @return array
4647
* @throws NoSuchEntityException
4748
*/
48-
public function getData(string $postId): array
49+
public function getData(string $postId, array $fields): array
4950
{
5051
$post = $this->postRepository->getFactory()->create();
5152
$post->getResource()->load($post, $postId);
@@ -54,6 +55,6 @@ public function getData(string $postId): array
5455
throw new NoSuchEntityException();
5556
}
5657

57-
return $post->getDynamicData();
58+
return $post->getDynamicData($fields);
5859
}
5960
}

Model/Resolver/Post.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function resolve(
4444
array $value = null,
4545
array $args = null
4646
) {
47+
$fields = $info->getFieldSelection();
4748
$postId = $this->getPostId($args);
48-
$postData = $this->getPostData($postId);
49-
return $postData;
49+
return $this->getPostData($postId, $fields);
5050
}
5151

5252
/**
@@ -65,13 +65,14 @@ private function getPostId(array $args): string
6565

6666
/**
6767
* @param string $postId
68+
* @param array $fields
6869
* @return array
6970
* @throws GraphQlNoSuchEntityException
7071
*/
71-
private function getPostData(string $postId): array
72+
private function getPostData(string $postId, array $fields): array
7273
{
7374
try {
74-
$postData = $this->postDataProvider->getData($postId);
75+
$postData = $this->postDataProvider->getData($postId, $fields);
7576
} catch (NoSuchEntityException $e) {
7677
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
7778
}

Model/Resolver/Posts.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ public function resolve(
101101
}
102102

103103
$items = $searchResult->getItems();
104+
$fields = $info->getFieldSelection(1);
104105

105106
foreach ($items as $k => $data) {
106-
$items[$k] = $this->postDataProvider->getData($data['post_id']);
107+
$items[$k] = $this->postDataProvider->getData($data['post_id'], $fields['items']);
107108
}
108109

109110
return [

etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ type BlogPost {
117117
is_recent_posts_skip: Int @doc(description: "Blog Post Is recent posts skip")
118118
short_content: String @doc(description: "Blog Post Short content")
119119
related_posts: [BlogPost] @doc(description: "Blog Related posts")
120-
related_products: [ProductInterface] @doc(description: "Blog Related products")
120+
related_products: [String] @doc(description: "Blog Related products")
121121
#fb_auto_publish: Int @doc(description: "Blog Post Fb auto publish")
122122
#fb_post_format: String @doc(description: "Blog Post Fb post format")
123123
#fb_published: Int @doc(description: "Blog Post Fb published")

0 commit comments

Comments
 (0)