diff --git a/VERSIONS_HOTLINE/82201 b/VERSIONS_HOTLINE/82201 new file mode 100644 index 0000000000000000000000000000000000000000..a457a0c226ff324c39c8074efe6853c0645a5195 --- /dev/null +++ b/VERSIONS_HOTLINE/82201 @@ -0,0 +1 @@ + - ticket #82201 : Cosmogramme : optimisation de l'indexation des ressources numériques \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_362.php b/cosmogramme/sql/patch/patch_362.php new file mode 100644 index 0000000000000000000000000000000000000000..df34b548f27d8fd2ca24dc1c5865c77bb54b1ec3 --- /dev/null +++ b/cosmogramme/sql/patch/patch_362.php @@ -0,0 +1,5 @@ +<?php +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); +try { + $adapter->query('ALTER TABLE album ADD KEY date_maj (date_maj)'); +} catch(Exception $e) {} diff --git a/library/Class/Album.php b/library/Class/Album.php index 00327be53a755aa1122ed5b7648c1cf989664eb6..0252f6b3066be0d103a49b6cb3c5eb1007f5a01f 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -54,7 +54,6 @@ */ class AlbumLoader extends Storm_Model_Loader { - use Trait_MemoryCleaner; @@ -82,6 +81,14 @@ class AlbumLoader extends Storm_Model_Loader { $page++; } } + + + public function findAllAfter($id, $date_maj, $limit=100) { + $where = "id > " . $id . " and date_maj >= '" . $date_maj . "'"; + return Class_Album::findAllBy(['where' => $where, + 'order' => 'id', + 'limit' => $limit]); + } } @@ -173,6 +180,8 @@ class Class_Album extends Storm_Model_Abstract { protected $path_flash; + protected $_date_maj_enabled = true; + public function __construct() { parent::__construct(); @@ -901,6 +910,13 @@ class Class_Album extends Storm_Model_Abstract { } + public function saveWithoutDateMaj() { + $this->_date_maj_enabled = false; + $this->save(); + $this->_date_maj_enabled = true; + } + + public function collectAuthors() { $authors = $this->_collect('authors', self::AUTHOR_FIELD); if(isset($authors['author'])) @@ -944,6 +960,9 @@ class Class_Album extends Storm_Model_Abstract { public function updateDateMaj() { + if (!$this->_date_maj_enabled) + return $this; + return $this->setDateMaj(date('Y-m-d H:i:s', self::getTimeSource()->time())); } diff --git a/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php b/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php index 3f47f68b5248bc4c843911d7f736b120105638a7..e5040754c2fc215c8b0e6d0aaba2c597ded71469 100644 --- a/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php +++ b/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php @@ -24,7 +24,9 @@ abstract class Class_Cosmogramme_Integration_PhasePseudoRecord extends Class_Cosmogramme_Integration_PhaseAbstract { use Trait_MemoryCleaner; - protected $_model_id_field, $_memory_cleaner; + protected + $_model_id_field, + $_previous_page = []; /** @var Trait_Indexable */ protected $_model_name; @@ -53,6 +55,9 @@ abstract class Class_Cosmogramme_Integration_PhasePseudoRecord if ($this->isTimeOut()) return; + if ($this->_isPreviousPage($models)) + break; + $this->_runPage($models); $this->_cleanMemory(); } @@ -61,6 +66,16 @@ abstract class Class_Cosmogramme_Integration_PhasePseudoRecord } + protected function _isPreviousPage($page) { + if ($this->_previous_page + && !array_filter(array_diff($this->_previous_page, $page))) + return true; + + $this->_previous_page = $page; + return false; + } + + protected function _runPage($models) { $this->_log->log($this->_getData('nombre') . '<br>'); foreach($models as $model) { diff --git a/library/Class/Cosmogramme/Integration/PhasePseudoRecordAlbum.php b/library/Class/Cosmogramme/Integration/PhasePseudoRecordAlbum.php index 4a798cd03e7c0d376b00a98fbb48d2a68a9566a0..c616e66bbee291dc5680bc66bc4f914452c5b5e8 100644 --- a/library/Class/Cosmogramme/Integration/PhasePseudoRecordAlbum.php +++ b/library/Class/Cosmogramme/Integration/PhasePseudoRecordAlbum.php @@ -25,10 +25,39 @@ class Class_Cosmogramme_Integration_PhasePseudoRecordAlbum extends Class_Cosmogr protected $_label = 'Pseudo-notices : RESSOURCES NUMERIQUES'; protected $_model_name = 'Class_Album'; + protected $_last_update_date; /** @return array **/ protected function _previousPhaseIds() { return [0.4]; } + + + protected function _loadPage() { + $this->_cleanMemory(); + return Class_Album::findAllAfter($this->_getData('pointeur_reprise'), + $this->_getData('pointeur')); + } + + + protected function _runOne($model) { + parent::_runOne($model); + $this->_last_update_date = $model->getDateMaj(); + } + + + protected function _init($phase) { + parent::_init($phase); + $phase->setData('pointeur', + ($last_date = Class_CosmoVar::getValueOf('date_maj_albums')) + ? $last_date + : '0000-00-00 00:00:00'); + } + + + protected function _summarize() { + Class_CosmoVar::setValueOf('date_maj_albums', $this->getCurrentDateTime()); + parent::_summarize(); + } } diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index 16f58ab1afb965985e0037199e278cdb6a3d4ed9..7d2670310671858c11e13738bd37d2443a4e5cc8 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -80,12 +80,16 @@ class Class_Indexation_PseudoNotice { if (!$this->_ensureItem()) return false; + $this->_updateLinkToRecord(); + $this->_index(); + return true; + } + + + protected function _updateLinkToRecord() { $this->_model ->updateAttributes([$this->_id_notice => $this->_notice->getId()]) ->save(); - - $this->_index(); - return true; } @@ -235,9 +239,6 @@ class Class_Indexation_PseudoNotice { $this->_notice->save(); $this->_indexItem(); - - $this->_model->setNotice($this->_notice) - ->save(); } @@ -437,6 +438,13 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ } + protected function _updateLinkToRecord() { + $this->_model + ->setNoticeId($this->_notice->getId()) + ->saveWithoutDateMaj(); + } + + protected function _modelIdAcceptVisitor($visitor) {} diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 2a93c139cb49430425f199046b61e1623947fb53..37d07dcdd7ef9fc6ed0de157722f971effe95f4d 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -2405,4 +2405,18 @@ class UpgradeDB_361_Test extends UpgradeDBTestCase { public function idOrigineLengthShouldBe255() { $this->assertFieldType('album','id_origine', 'varchar(255)'); } +} + + + +class UpgradeDB_362_Test extends UpgradeDBTestCase { + public function prepare() { + $this->silentQuery('ALTER TABLE album drop KEY date_maj'); + } + + + /** @test */ + public function dateMajShouldBeIndexed() { + $this->assertIndex('album', 'date_maj'); + } } \ No newline at end of file diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php index a09e4baf1208c19b08ff9e4d90bc69b1ded19690..c9f694ee7cf97d8a6b44c4b508298a81e343cd1b 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php @@ -36,21 +36,22 @@ abstract class PhasePseudoRecordTestCase extends Class_Cosmogramme_Integration_P protected function _prepareFixtures() { - $loader = $this->onLoaderOfModel($this->_model_name) + $loader = $this + ->onLoaderOfModel($this->_model_name) - ->whenCalled('findAllBy') - ->with(['where' => $this->_model_id . ' > 0', - 'order' => $this->_model_id, - 'limit' => 100]) - ->answers([$this->_buildModel(15)]) + ->whenCalled('findAllBy') + ->with(['where' => $this->_model_id . ' > 0', + 'order' => $this->_model_id, + 'limit' => 100]) + ->answers([$this->_buildModel(15)]) - ->whenCalled('findAllBy') - ->with(['where' => $this->_model_id . ' > 15', - 'order' => $this->_model_id, - 'limit' => 100]) - ->answers([$this->_buildModel(16)]) + ->whenCalled('findAllBy') + ->with(['where' => $this->_model_id . ' > 15', + 'order' => $this->_model_id, + 'limit' => 100]) + ->answers([$this->_buildModel(16)]) - ->whenCalled('findAllBy')->answers([]); + ->whenCalled('findAllBy')->answers([]); } @@ -423,11 +424,42 @@ abstract class PhasePseudoRecordAlbumTestCase extends PhasePseudoRecordTestCase $_model_name = 'Class_Album', $_model_id = 'id'; + protected function _prepareFixtures() { + Class_Cosmogramme_Integration_PhasePseudoRecordAlbum::setTimeSource(new TimeSourceForTest('2019-01-09 12:11:38')); + + Class_CosmoVar::setValueOf('date_maj_albums', '2018-12-18 17:21:54'); + + $loader = $this + ->onLoaderOfModel($this->_model_name) + ->whenCalled('findAllBy') + ->with(['where' => $this->_model_id . ' > 0 and date_maj >= \'2018-12-18 17:21:54\'', + 'order' => $this->_model_id, + 'limit' => 100]) + ->answers([$this->_buildModel(15)]) + + ->whenCalled('findAllBy') + ->with(['where' => $this->_model_id . ' > 15 and date_maj >= \'2018-12-18 17:21:54\'', + 'order' => $this->_model_id, + 'limit' => 100]) + ->answers([$this->_buildModel(16)]) + + ->whenCalled('findAllBy')->answers([]) + ; + } + + + public function tearDown() { + Class_Cosmogramme_Integration_PhasePseudoRecordAlbum::setTimeSource(null); + parent::tearDown(); + } + + protected function _getModelAttribs($id) { return array_merge(parent::_getModelAttribs($id), ['titre' => 'Album ' . $id, 'visible' => 1, - 'status' => Class_Album::STATUS_VALIDATED]); + 'status' => Class_Album::STATUS_VALIDATED, + 'date_maj' => '2018-12-18 17:21:54']); } } @@ -472,6 +504,13 @@ class PhasePseudoRecordAlbumValidInteractiveCallbackTest ->beCallBack() ->setData('nombre', 1) ->setData('pointeur_reprise', 15) + ->setData('pointeur', '2018-12-18 17:21:54') ->setCount(Class_Cosmogramme_Integration_Phase::RECORD_INSERT, 6); } + + + /** @test */ + public function dateMajAlbumsShouldBeUpdated() { + $this->assertEquals('2019-01-09 12:11:38', Class_CosmoVar::get('date_maj_albums')); + } } \ No newline at end of file