mirror of
https://github.com/grocy/grocy.git
synced 2025-08-21 04:43:32 +00:00
Optimized performance of CurrentVolatileStock
This commit is contained in:
@@ -619,19 +619,25 @@ class StockService extends BaseService
|
|||||||
return $pluginOutput;
|
return $pluginOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static $CurrentStockCache = null;
|
||||||
public function GetCurrentStock()
|
public function GetCurrentStock()
|
||||||
{
|
{
|
||||||
$sql = 'SELECT * FROM stock_current';
|
if (self::$CurrentStockCache == null)
|
||||||
$currentStockMapped = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_OBJ);
|
|
||||||
$relevantProducts = $this->getDatabase()->products()->where('id IN (SELECT product_id FROM (' . $sql . ') x)');
|
|
||||||
|
|
||||||
foreach ($relevantProducts as $product)
|
|
||||||
{
|
{
|
||||||
$currentStockMapped[$product->id][0]->product_id = $product->id;
|
$sql = 'SELECT * FROM stock_current';
|
||||||
$currentStockMapped[$product->id][0]->product = $product;
|
$currentStockMapped = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_OBJ);
|
||||||
|
$relevantProducts = $this->getDatabase()->products()->where('id IN (SELECT product_id FROM (' . $sql . ') x)');
|
||||||
|
|
||||||
|
foreach ($relevantProducts as $product)
|
||||||
|
{
|
||||||
|
$currentStockMapped[$product->id][0]->product_id = $product->id;
|
||||||
|
$currentStockMapped[$product->id][0]->product = $product;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$CurrentStockCache = array_column($currentStockMapped, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_column($currentStockMapped, 0);
|
return self::$CurrentStockCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetCurrentStockLocationContent($includeOutOfStockProductsAtTheDefaultLocation = false)
|
public function GetCurrentStockLocationContent($includeOutOfStockProductsAtTheDefaultLocation = false)
|
||||||
|
Reference in New Issue
Block a user