Skip to content

Commit

Permalink
Breaking products into smaller chunks for more efficient loading
Browse files Browse the repository at this point in the history
  • Loading branch information
markmiddleton committed Oct 20, 2023
1 parent e50e9e1 commit 9098c01
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/jobs/AlgoliaChunkLoadTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,28 @@ public function execute($queue)

CASE 'variant':

AlgoliaSync::$plugin->algoliaSyncService->logger("loading a chunck of variants into the Algolia sync queue", basename(__FILE__) , __LINE__);
AlgoliaSync::$plugin->algoliaSyncService->logger("loading a chunk of product variants into the Algolia sync queue", basename(__FILE__) , __LINE__);

$commercePlugin = Craft::$app->plugins->getPlugin('commerce');

if ($commercePlugin) {

$variants = \craft\commerce\elements\Variant::find()->typeId($sectionId)->status('enabled')->all();
$recordCount = \craft\commerce\elements\Variant::find()->typeId($sectionId)->offset($offsetCount)->limit($limitCount)->status('enabled')->count();
$variants = \craft\commerce\elements\Variant::find()->typeId($sectionId)->offset($offsetCount)->limit($limitCount)->status('enabled')->all();

$recordCount = count($variants);
if ($recordCount > 0) {
AlgoliaSync::$plugin->algoliaSyncService->logger("Now loading ".$recordCount." products to be synced", basename(__FILE__) , __LINE__);

AlgoliaSync::$plugin->algoliaSyncService->logger("Now loading ".$recordCount." products to be synced", basename(__FILE__) , __LINE__);
$currentLoopCount = 0;
foreach ($variants as $variant) {
$progress = $currentLoopCount / $recordCount;
$this->setProgress($queue, $progress);

$currentLoopCount = 0;
foreach ($variants as $variant) {
$progress = $currentLoopCount / $recordCount;
$this->setProgress($queue, $progress);
AlgoliaSync::$plugin->algoliaSyncService->logger(print_r($variant, true), basename(__FILE__) , __LINE__);

AlgoliaSync::$plugin->algoliaSyncService->logger(print_r($variant, true), basename(__FILE__) , __LINE__);

AlgoliaSync::$plugin->algoliaSyncService->prepareAlgoliaSyncElement($variant);
$currentLoopCount++;
AlgoliaSync::$plugin->algoliaSyncService->prepareAlgoliaSyncElement($variant);
$currentLoopCount++;
}
}
}
break;
Expand Down

0 comments on commit 9098c01

Please sign in to comment.