-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: data sync performance optimisation #634
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Dotdigitalgroup\Email\Model\Connector; | ||
|
||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource; | ||
use Magento\Catalog\Model\ResourceModel\Category\Collection; | ||
|
||
class Category | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $categoryNames = []; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
protected StoreManagerInterface $storeManager; | ||
|
||
/** | ||
* @var Collection | ||
*/ | ||
protected Collection $categoryCollection; | ||
|
||
/** | ||
* @var CategoryResource | ||
*/ | ||
protected CategoryResource $categoryResource; | ||
|
||
/** | ||
* @param StoreManagerInterface $storeManager | ||
* @param Collection $categoryCollection | ||
* @param CategoryResource $categoryResource | ||
*/ | ||
public function __construct( | ||
StoreManagerInterface $storeManager, | ||
Collection $categoryCollection, | ||
CategoryResource $categoryResource | ||
) { | ||
$this->storeManager = $storeManager; | ||
$this->categoryCollection = $categoryCollection; | ||
$this->categoryResource = $categoryResource; | ||
$this->init(); | ||
} | ||
|
||
/** | ||
* @return Category | ||
*/ | ||
public function init() | ||
{ | ||
foreach ($this->categoryCollection->setPageSize(10000)->load() as $category) { | ||
/** @var Category $category */ | ||
foreach ($this->storeManager->getStores() as $store) { | ||
$category->setStoreId($store->getId()); | ||
$this->categoryResource->load($category, $category->getId()); | ||
if (!array_key_exists($category->getId(), $this->categoryNames)) { | ||
$this->categoryNames[$category->getId()] = []; | ||
} | ||
if (!array_key_exists($store->getId(), $this->categoryNames[$category->getId()])) { | ||
$this->categoryNames[$category->getId()][$store->getId()] = null; | ||
} | ||
$this->categoryNames[$category->getId()][$store->getId()] = $category->getName(); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* | ||
* Get category names. | ||
* | ||
* @param array $categoryIds | ||
* @return string | ||
*/ | ||
public function getCategoryNames($categoryIds, $storeId): string | ||
{ | ||
$names = []; | ||
foreach ($categoryIds as $id) { | ||
if (array_key_exists($id, $this->categoryNames) | ||
&& array_key_exists($storeId, $this->categoryNames[$id])) { | ||
$names[$id] = $this->categoryNames[$id][$storeId]; | ||
} | ||
} | ||
|
||
//comma separated category names | ||
if (count($names)) { | ||
return implode(',', $names); | ||
} | ||
|
||
return ''; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ public function __construct( | |
*/ | ||
public function apply() | ||
{ | ||
$this->automationFactory->create()->sync(); | ||
//$this->automationFactory->create()->sync(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assumption is that this model is not used by CLI/cron job and this change won't prevent automation processing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This patch was added when we introduced queues for automation processing. It was possible at point of upgrade that a merchant still has some residual automations in the table (up to 15 mins' worth) which would not be queued and therefore left to become stale. Without this merchants would need to remember / be reminded to do this to process remaining old-style automations. |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why this is necessary if the class was injected in the constructor in the usual way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sta1r
That snippet was maintained there since the original solution was applied as a patch. You are right, DI should suffice and the use of objectManager to be deleted/discouraged.