increase speed
This commit is contained in:
@@ -22,6 +22,8 @@ class ProductRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, Product::class);
|
||||
}
|
||||
|
||||
private $batch = [];
|
||||
|
||||
public function save(Product $entity, bool $flush = false): ?int
|
||||
{
|
||||
|
||||
@@ -48,7 +50,7 @@ class ProductRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* @return Product[] Returns an array of Product objects
|
||||
*/
|
||||
public function findById($value): array
|
||||
public function findById(int $value): array
|
||||
{
|
||||
return $this->createQueryBuilder('p')
|
||||
->andWhere('p.id IN (:val)')
|
||||
@@ -57,13 +59,22 @@ class ProductRepository extends ServiceEntityRepository
|
||||
->getResult();
|
||||
}
|
||||
|
||||
// public function findOneBySomeField($value): ?Product
|
||||
// {
|
||||
// return $this->createQueryBuilder('p')
|
||||
// ->andWhere('p.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
public function add(Product $product): void
|
||||
{
|
||||
$this->batch[] = $product;
|
||||
}
|
||||
|
||||
public function saveAll(): array
|
||||
{
|
||||
$product_ids = [];
|
||||
|
||||
foreach ($this->batch as $product) {
|
||||
$product->setUpdateTime(new DateTime());
|
||||
$this->getEntityManager()->persist($product);
|
||||
$product_ids[] = $product->getId();
|
||||
}
|
||||
$this->getEntityManager()->flush();
|
||||
return $product_ids;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,8 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class StockRepository extends ServiceEntityRepository
|
||||
{
|
||||
private $batch = [];
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Stock::class);
|
||||
@@ -45,7 +47,7 @@ class StockRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* @return Stock[] Returns an array of Stock objects
|
||||
*/
|
||||
public function findByWarehouseId($warehouseId): array
|
||||
public function findByWarehouseId(int $warehouseId): array
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->join('s.warehouse', 'w')
|
||||
@@ -56,13 +58,21 @@ class StockRepository extends ServiceEntityRepository
|
||||
->getResult();
|
||||
}
|
||||
|
||||
// public function findOneBySomeField($value): ?Stock
|
||||
// {
|
||||
// return $this->createQueryBuilder('s')
|
||||
// ->andWhere('s.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
public function add(Stock $stock): void
|
||||
{
|
||||
$this->batch[] = $stock;
|
||||
}
|
||||
|
||||
public function saveAll(): void
|
||||
{
|
||||
if (empty($this->batch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->batch as $stock) {
|
||||
$this->getEntityManager()->persist($stock);
|
||||
}
|
||||
$this->getEntityManager()->flush();
|
||||
$this->batch = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user