Skip to content

Commit 7c81f84

Browse files
committed
Performance improvements
1 parent b5e96a5 commit 7c81f84

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

Model/Post.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,10 @@ public function initDinamicData()
955955

956956
/**
957957
* Prepare all additional data
958+
* @param null $fields
958959
* @return array
959960
*/
960-
public function getDynamicData()
961+
public function getDynamicData($fields = null)
961962
{
962963
$data = $this->getData();
963964

@@ -984,31 +985,39 @@ public function getDynamicData()
984985
$data[$key] = $this->$method();
985986
}
986987

987-
$tags = [];
988-
foreach ($this->getRelatedTags() as $tag) {
989-
$tags[] = $tag->getDynamicData();
988+
if (array_key_exists('tags', $fields)) {
989+
$tags = [];
990+
foreach ($this->getRelatedTags() as $tag) {
991+
$tags[] = $tag->getDynamicData();
992+
}
993+
$data['tags'] = $tags;
990994
}
991-
$data['tags'] = $tags;
992995

993-
$relatedPosts = [];
994-
foreach ($this->getRelatedPosts() as $relatedPost) {
995-
$relatedPosts[] = $relatedPost->getDynamicData();
996+
if (array_key_exists('related_posts', $fields)) {
997+
$relatedPosts = [];
998+
foreach ($this->getRelatedPosts() as $relatedPost) {
999+
$relatedPosts[] = $relatedPost->getDynamicData($fields);
1000+
}
1001+
$data['related_posts'] = $relatedPosts;
9961002
}
997-
$data['related_posts'] = $relatedPosts;
9981003

999-
$relatedProducts = [];
1000-
foreach ($this->getRelatedProducts() as $relatedProduct) {
1001-
$relatedProducts[] = $relatedProduct->getData();
1004+
if (array_key_exists('related_products', $fields)) {
1005+
$relatedProducts = [];
1006+
foreach ($this->getRelatedProducts() as $relatedProduct) {
1007+
$relatedProducts[] = $relatedProduct->getSku();
1008+
}
1009+
$data['related_products'] = $relatedProducts;
10021010
}
1003-
$data['related_products'] = $relatedProducts;
10041011

1005-
$categories = [];
1006-
foreach ($this->getParentCategories() as $category) {
1007-
$categories[] = $category->getDynamicData();
1012+
if (array_key_exists('categories', $fields)) {
1013+
$categories = [];
1014+
foreach ($this->getParentCategories() as $category) {
1015+
$categories[] = $category->getDynamicData();
1016+
}
1017+
$data['categories'] = $categories;
10081018
}
1009-
$data['categories'] = $categories;
10101019

1011-
if ($author = $this->getAuthor()) {
1020+
if (array_key_exists('author', $fields) && $author = $this->getAuthor()) {
10121021
$data['author'] = $author->getDynamicData();
10131022
}
10141023

0 commit comments

Comments
 (0)