Skip to content
Snippets Groups Projects
Commit 50686858 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch...

Merge branch 'hotline#37385_phase_de_suppression_des_notices_sans_exemplaires_trop_longue' into 'stable'

Hotline#37385 phase de suppression des notices sans exemplaires trop longue

See merge request !1438
parents 22688e1a 8b9f14af
Branches
Tags
8 merge requests!1553Master,!1519Master,!1502Master,!1501Stable,!1491Master,!1472Stable,!1461Stable,!1454Stable
- ticket #37385 : Réduction du temps de la phase de suppression des notices sans exemplaires
......@@ -35,6 +35,20 @@ abstract class Class_Cosmogramme_Integration_PhaseAbstract {
}
public function setSqlAdapter($adapter) {
$this->_sql_adapter = $adapter;
return $this;
}
protected function getSqlAdapter() {
if(!$this->_sql_adapter)
$this->_sql_adapter = Zend_Db_Table::getDefaultAdapter();
return $this->_sql_adapter;
}
protected abstract function _execute();
protected abstract function _init($phase);
......@@ -134,4 +148,16 @@ abstract class Class_Cosmogramme_Integration_PhaseAbstract {
return !$this->_phase->isCron()
&& $this->_chrono->mainElapsed() > $this->_chrono->timeout();
}
protected function _resetDbConnection() {
if (!$this->_db_reset)
return $this;
Storm_Model_Abstract::unsetLoaders();
Zend_Db_Table::getDefaultAdapter()->closeConnection();
setupDatabase(loadConfig());
gc_collect_cycles();
return $this;
}
}
\ No newline at end of file
......@@ -26,46 +26,41 @@ class Class_Cosmogramme_Integration_PhaseDeleteRecordWithoutItem extends Class_C
protected $_label = 'Suppression des notices sans exemplaire';
public function _execute() {
if ($this->isTimeOut())
return $this->_phase;
$this->_chrono->start();
$page_size = 1000;
$page = 1;
$page_size = 100;
$page = 0;
while($records_ids = $this->getSqlAdapter()->fetchAll('SELECT notices.id_notice FROM notices WHERE notices.id_notice NOT IN (SELECT exemplaires.id_notice FROM exemplaires) LIMIT ' . $page . ', ' . $page_size)) {
while ($notices = Class_Notice::findAllBy(['order' => 'id_notice',
'limitPage' => [$page, $page_size]])) {
foreach ($notices as $notice) {
$this->_runOne($notice);
}
if ($this->isTimeOut())
return $this->_resetDbConnection()
->_phase;
foreach ($records_ids as $record_id)
$this->_runOne($record_id['id_notice']);
$this->_log->ecrire($this->_getData('deleted') . ' notices sans exemplaire supprimées<br/>');
$this->_cleanMemory();
$page++;
}
if (0 == $this->_getData('deleted'))
if (0 == $this->_getData('deleted')) {
$this->_log->ecrire('Aucune notice sans exemplaire');
return;
}
if (0 < $this->_getData('deleted'))
$this->_log->ecrire($this->_getData('deleted').' notices sans exemplaire supprimées');
$this->_log->ecrire('Temps de traitement: '.$this->_chrono->endMain().' ('.$this->_chrono->mainAverage($this->_getData('nombre'), 'notices').')' );
$this->_log->ecrire('Temps de traitement: '.$this->_chrono->endMain().' ('.$this->_chrono->mainAverage($this->_getData('deleted'), 'notices').')' );
}
protected function _runOne($notice) {
$this->_incrementData('nombre');
if ($notice->hasExemplaires())
return;
$notice->delete();
protected function _runOne($record_id) {
Class_Notice::find($record_id)->delete();
$this->_incrementData('deleted');
}
protected function _init($phase) {
$phase
->resetDatas()
->setData('nombre', 0)
->setData('deleted', 0);
}
}
......@@ -128,18 +128,5 @@ class Class_Cosmogramme_Integration_PhaseItemFacets
$this->_db_reset = false;
return $this;
}
protected function _resetDbConnection() {
if (!$this->_db_reset)
return $this;
Storm_Model_Abstract::unsetLoaders();
Zend_Db_Table::getDefaultAdapter()->closeConnection();
setupDatabase(loadConfig());
gc_collect_cycles();
return $this;
}
}
?>
\ No newline at end of file
......@@ -21,13 +21,13 @@
abstract class PhaseDeleteRecordWithoutItemTestCase extends Class_Cosmogramme_Integration_PhaseTestCase {
protected $_phase;
protected $_phase, $_mock_sql;
public function setUp() {
parent::setUp();
$this->_phase = $this->_buildPhase('DeleteRecordWithoutItem')
->setMemoryCleaner(function() {})
->setSqlAdapter($this->_mock_sql)
->run();
Class_Notice::clearCache();
Class_Exemplaire::clearCache();
......@@ -64,13 +64,26 @@ abstract class PhaseDeleteRecordWithoutItemTestCase extends Class_Cosmogramme_In
class PhaseDeleteRecordWithoutItemSimpleTest extends PhaseDeleteRecordWithoutItemTestCase {
protected function _prepareFixtures() {
parent::_prepareFixtures();
$this->fixture('Class_Notice', ['id' => 34]);
$this->fixture('Class_Notice', ['id' => 35]);
$this->_mock_sql = Storm_Test_ObjectWrapper::mock();
$this->_mock_sql
->whenCalled('fetchAll')
->with('SELECT notices.id_notice FROM notices WHERE notices.id_notice NOT IN (SELECT exemplaires.id_notice FROM exemplaires) LIMIT 0, 100')
->answers([0 => ['id_notice' => 34],
1 => ['id_notice' => 35]])
->whenCalled('fetchAll')
->with('SELECT notices.id_notice FROM notices WHERE notices.id_notice NOT IN (SELECT exemplaires.id_notice FROM exemplaires) LIMIT 1, 100')
->answers([])
->beStrict();
}
......@@ -90,6 +103,18 @@ class PhaseDeleteRecordWithoutItemSimpleTest extends PhaseDeleteRecordWithoutIte
class PhaseDeleteRecordWithoutItemNothingToDeleteTest extends PhaseDeleteRecordWithoutItemTestCase {
protected function _prepareFixtures() {
parent::_prepareFixtures();
$this->_mock_sql = Storm_Test_ObjectWrapper::mock();
$this->_mock_sql
->whenCalled('fetchAll')
->with('SELECT notices.id_notice FROM notices WHERE notices.id_notice NOT IN (SELECT exemplaires.id_notice FROM exemplaires) LIMIT 0, 100')
->answers([])
->beStrict();
}
/** @test */
public function totalNumberOfRecordsShouldBe3() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment