에서 여러 행에 대해 하나의 Insert 문을 발행하면 각 객체에서 save() 메서드를 호출하는 대신 INSERT 문 하나를 실행할 수 있습니까? PropelObjectCollection에서 save()를 호출 할 수 있습니까?Propel
Q
Propel
0
A
답변
1
PropelObjectCollection에서 클래스 자체에서 save를 호출 할 수 있지만 작업을 수행하기 위해 여러 삽입 문을 실행합니다.
Propel이 기본적으로 수행하는 트랜잭션에 모두 래핑 된 경우 INSERT를 여러 번 실행하는 것보다 많은 성능 향상을 얻지는 못합니다. 또한 Propel이 관련 객체를 저장하기 위해 재귀하는 방식을 감안할 때이 작업을 수행하려는 것으로 의심되는 경우 많은 복잡성이 추가됩니다.
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Class for iterating over a list of Propel objects
*
* @author Francois Zaninotto
* @package propel.runtime.collection
*/
class PropelObjectCollection extends PropelCollection
{
/**
* Save all the elements in the collection
*
* @param PropelPDO $con
*
* @throws PropelException
*/
public function save($con = null)
{
if (!method_exists($this->getModel(), 'save')) {
throw new PropelException('Cannot save objects on a read-only model');
}
if (null === $con) {
$con = $this->getConnection(Propel::CONNECTION_WRITE);
}
$con->beginTransaction();
try {
/** @var $element BaseObject */
foreach ($this as $element) {
$element->save($con);
}
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
0
당신의 저장을 모두 넣어 충분하다()는 하나의 트랜잭션 내에서 호출합니다. 필자는 MySQL 데이터베이스에 270 개의 레코드를 삽입해야했다. 거래없이
결과 : 실제 0m15.127s 사용자가 트랜잭션과 에 sys 0m0.056s
결과 0m0.300s : 실제 0m0.687s 사용자가 에 sys 0m0.036s
을 0m0.244s 큰 차이가 있습니다.