Skip to content

Commit

Permalink
Summary loading optimization (#2)
Browse files Browse the repository at this point in the history
* Took summary from collection, instead of loading it each time. TODO: add dependecy to catalog-graphql.

* Added catalog graphql deps
  • Loading branch information
alfredsgenkins authored Oct 23, 2019
1 parent f92b2f8 commit a7bd39a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "N/A",
"type": "magento2-module",
"require": {
"magento/magento2-base": "^2.3.1"
"magento/magento2-base": "^2.3.1",
"scandipwa/catalog-graphql": "^2.2.0"
},
"support": {
"source": "https://github.com/scandipwa/reviews-graphql",
Expand Down
17 changes: 3 additions & 14 deletions src/Model/Resolver/Product/ReviewSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
*/
class ReviewSummary implements ResolverInterface
{
/**
* @var ReviewFactory
*/
protected $reviewFactory;

/**
* @var StoreManagerInterface
*/
Expand All @@ -43,14 +38,11 @@ class ReviewSummary implements ResolverInterface
/**
* ReviewSummary constructor.
*
* @param ReviewFactory $reviewFactory
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ReviewFactory $reviewFactory,
StoreManagerInterface $storeManager
) {
$this->reviewFactory = $reviewFactory;
$this->storeManager = $storeManager;
}

Expand All @@ -70,14 +62,11 @@ public function resolve(

/** @var Product $product */
$product = $value['model'];
$storeId = $this->storeManager->getStore()->getId();
$this->reviewFactory->create()->getEntitySummary($product, $storeId);
$ratingSummary = $product->getRatingSummary()->getRatingSummary();
$reviewCount = $product->getRatingSummary()->getReviewsCount();
$ratingSummary = $product->getRatingSummary();

return [
'rating_summary' => $ratingSummary,
'review_count' => $reviewCount
'rating_summary' => $ratingSummary->getRatingSummary(),
'review_count' => $ratingSummary->getReviewsCount()
];
}
}

0 comments on commit a7bd39a

Please sign in to comment.