Skip to content

Commit

Permalink
fix: use id instead of SKU (#39)
Browse files Browse the repository at this point in the history
Use entity_id in the WHERE clause instead of sku. This adjustment enhances the query's speed, especially when dealing with a large number of products.

During local testing, the export time decreased significantly from 50 minutes to just 8 minutes. Resulting in an increase in speed of 84%. This speed increase only seems to occur if you don't have all numbers as sku's.
  • Loading branch information
ah-net authored Mar 29, 2024
1 parent 387f2ef commit 7b325cb
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getStockItemMap(Collection|StockCollection $collection): array
return [];
}

$skus = $collection->getAllSkus();
$entityIds = $collection->getAllIds();

$store = $collection->getStore();
$sourceCodes = $this->getSourceCodesForStore($store);
Expand Down Expand Up @@ -159,7 +159,7 @@ public function getStockItemMap(Collection|StockCollection $collection): array
->select()
->from($stockItemTable)
->reset('columns')
->where("$stockItemTable.product_id IN (?)", $collection->getAllIds())
->where("$stockItemTable.product_id IN (?)", $entityIds)
/*
$stock_id is in this case the default stock id (i.e. 1) this filter problably doesnt remove anything
but it is here just to be sure.
Expand Down Expand Up @@ -207,7 +207,7 @@ public function getStockItemMap(Collection|StockCollection $collection): array
'backorders',
]
)
->where("$productTableName.sku IN (?)", $skus)
->where("$productTableName.entity_id IN (?)", $entityIds)
->columns(
[
'product_entity_id' => "$productTableName.entity_id",
Expand Down

0 comments on commit 7b325cb

Please sign in to comment.