Commit 742d5d68 authored by Patrick Barroca's avatar Patrick Barroca 🐧

hotline #82201 : use date_maj as filter

parent 04eb193a
Pipeline #5905 passed with stage
in 60 minutes and 19 seconds
- ticket #82201 : Cosmogramme : optimisation de l'indexation des ressources numériques
\ No newline at end of file
<?php
$adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
try {
$adapter->query('ALTER TABLE album ADD KEY date_maj (date_maj)');
} catch(Exception $e) {}
......@@ -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()));
}
......
......@@ -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) {
......
......@@ -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();
}
}
......@@ -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) {}
......
......@@ -2392,3 +2392,18 @@ class UpgradeDB_360_Test extends UpgradeDBTestCase {
/** @test */
public function placeholderForSigbStandardCodificationsMigration() {}
}
class UpgradeDB_361_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
......@@ -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
Markdown is supported
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