diff --git a/VERSIONS_HOTLINE/202688 b/VERSIONS_HOTLINE/202688 new file mode 100644 index 0000000000000000000000000000000000000000..94cd37c1b0ac663c0907189355a09b852a919b1e --- /dev/null +++ b/VERSIONS_HOTLINE/202688 @@ -0,0 +1 @@ + - correctif #202688 : Fiche Abonné : Les sélections de paniers mettaient du temps à s'afficher. \ No newline at end of file diff --git a/library/Class/Notice/Loader.php b/library/Class/Notice/Loader.php index 84464b046241e6933f761a2a93b7db592741425f..58cf88731c7aa20e93e3c8161ed542bedc2989e6 100644 --- a/library/Class/Notice/Loader.php +++ b/library/Class/Notice/Loader.php @@ -23,6 +23,14 @@ class Class_Notice_Loader extends Storm_Model_Loader { use Trait_MemoryCleaner; + protected ?array $_records_alphas_keys = null; + + public function resetCacheRecord(): void + { + $this->_records_alphas_keys = null; + } + + public function getNoticesFromPreferences($preferences) { $requetes = Class_Catalogue::getRequetes($preferences); @@ -232,6 +240,20 @@ class Class_Notice_Loader extends Storm_Model_Loader { } + public function recordsFromAlphaKeys(array $alphas_keys): array + { + if ( ! $alphas_keys) + return []; + + $uniq_key = md5(implode('', $alphas_keys)); + + return $this->_records_alphas_keys[$uniq_key] ??= Class_Notice::query() + ->in('clef_alpha', $alphas_keys) + ->order(Storm_Query_Clause::orderField('clef_alpha', $alphas_keys)) + ->fetchAll(); + } + + public function dropIndexMotsNotice() : void { Zend_Registry::get('sql')->query('ALTER TABLE `notices` DROP INDEX IF EXISTS `mots_notice`'); } diff --git a/library/Class/PanierNotice.php b/library/Class/PanierNotice.php index 300bc110b00863454264cae586025a9a176eca68..3206d5b6ddb07f4885c362480f940083d0644cb4 100644 --- a/library/Class/PanierNotice.php +++ b/library/Class/PanierNotice.php @@ -213,19 +213,9 @@ class Class_PanierNotice extends Storm_Model_Abstract { } - public function getNoticesAsArray() : array { - return $this->getRecordsFromKeys($this->getClesNotices()); - } - - - public function getRecordsFromKeys(array $keys) : array { - if ($keys === []) - return []; - - return Class_Notice::findAllBy(['clef_alpha' => $keys, - 'order' => 'FIELD(clef_alpha, "' - . implode('","', $keys) - . '")']); + public function getNoticesAsArray(): array + { + return Class_Notice::recordsFromAlphaKeys($this->getClesNotices()); } diff --git a/library/Class/User/RecordCarts.php b/library/Class/User/RecordCarts.php index b9491641bc37a04cb1e1270ccf997735a39a7045..3b894a105dcf8948b74e49961edb1a72019df5fd 100644 --- a/library/Class/User/RecordCarts.php +++ b/library/Class/User/RecordCarts.php @@ -87,9 +87,10 @@ class Class_User_RecordCarts { } - public function getRecordsFromKeys() : array { - return $this->_cart - ? $this->_cart->getRecordsFromKeys($this->_record_keys->keys()) + public function getRecordsFromKeys(): array + { + return $this->_record_keys + ? Class_Notice::recordsFromAlphaKeys($this->_record_keys->keys()) : []; } } diff --git a/library/ZendAfi/View/Helper/Template/RenderingHorizontal.php b/library/ZendAfi/View/Helper/Template/RenderingHorizontal.php index 46b7945cfecb80c8c3c827479a4793d39247aba6..cb2b356586880b359919f869ec20432c28f3cae7 100644 --- a/library/ZendAfi/View/Helper/Template/RenderingHorizontal.php +++ b/library/ZendAfi/View/Helper/Template/RenderingHorizontal.php @@ -48,7 +48,7 @@ class ZendAfi_View_Helper_Template_RenderingHorizontal extends ZendAfi_View_Help if ($summary = $element->getDescription()) $content [] = $this->_tag('div', - $element->getDescription(), + $summary, ['title' => strip_tags($element->getDescriptionTitle()), 'class' => 'card-text']); diff --git a/library/templates/Intonation/Library/View/Wrapper/Selection.php b/library/templates/Intonation/Library/View/Wrapper/Selection.php index 380b8ff9e7622c9c667a8759b7216a70ab4b02cc..7135b7375a54bb572c1035854023e2692878ea8e 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Selection.php +++ b/library/templates/Intonation/Library/View/Wrapper/Selection.php @@ -20,13 +20,12 @@ */ -class Intonation_Library_View_Wrapper_Selection extends Intonation_Library_View_Wrapper_Abstract { - +class Intonation_Library_View_Wrapper_Selection extends Intonation_Library_View_Wrapper_Abstract +{ use Trait_InspectorGadget; - - protected $_count_records_cache; - + protected ?int $_count_records_cache = null; + protected ?array $_records_title = null; public function getMainTitle() { return $this->_model->getLibelle(); @@ -51,15 +50,11 @@ class Intonation_Library_View_Wrapper_Selection extends Intonation_Library_View_ } - public function getDescription() { - $records = $this->_model->getNoticesAsArray(); - $records_title = []; - foreach ($records as $record) - $records_title [] = $record->getTitrePrincipal(' '); - - $records_html = array_filter($records_title) + public function getDescription(): string + { + $records_html = $this->_recordsTitle() ? BR . $this->_('Liste des documents : %s', - $this->_view->truncate(implode(', ', $records_title), + $this->_view->truncate(implode(', ', $this->_recordsTitle()), ['class' => 'model_description_' . get_class($this->_model)])) : ''; @@ -78,17 +73,12 @@ class Intonation_Library_View_Wrapper_Selection extends Intonation_Library_View_ } - public function getFullDescription() { - $records = $this->_model->getNoticesAsArray(); - - $records_title = []; - foreach ($records as $record) - $records_title [] = $record->getTitrePrincipal(' '); - + public function getFullDescription(): string + { return $this->getBadges() . BR . $this->_('Liste des documents : %s', - implode(', ', $records_title)); + implode(', ', $this->_recordsTitle())); } @@ -284,11 +274,17 @@ class Intonation_Library_View_Wrapper_Selection extends Intonation_Library_View_ } - protected function _countRecords() : int { - if ( $this->_count_records_cache) - return $this->_count_records_cache; + protected function _countRecords(): int + { + return $this->_count_records_cache ??= count($this->_recordsTitle()); + } + - return $this->_count_records_cache = (int) $this->_model->numberOfNotices(); + protected function _recordsTitle(): array + { + return $this->_records_title + ??= array_filter(array_map(fn($record) => $record->getTitrePrincipal(' '), + $this->_model->getNoticesAsArray())); } diff --git a/tests/TearDown.php b/tests/TearDown.php index b6338c1b1694abd59363eae054abcc00fd984e20..0a4c2e88cce969ef0ed68511baec705204810292 100644 --- a/tests/TearDown.php +++ b/tests/TearDown.php @@ -71,6 +71,7 @@ class TearDown { Class_Notice::setTimeSource(null); Class_Facet::reset(); Class_StatsNotices::setTimeSource(null); + Class_Notice::resetCacheRecord(); Class_PanierNotice_RecordKeys::reset(); Intonation_Library_View_Wrapper_Record::resetUrlsByModelCache(); diff --git a/tests/library/Class/PanierNoticeTest.php b/tests/library/Class/PanierNoticeTest.php index dbbfe6d610796addf57e42c2fddcde2d9f74b930..85767755cb1af9fdd82d9e7a62b79f6c5db800fe 100644 --- a/tests/library/Class/PanierNoticeTest.php +++ b/tests/library/Class/PanierNoticeTest.php @@ -42,18 +42,16 @@ class PanierNoticeLoaderTestFindAllBelongsToAdmin extends ModelTestCase { -class PanierNoticeWithoutNoticesTest extends ModelTestCase { +class PanierNoticeWithoutNoticesTest extends ModelTestCase +{ + /** @test */ - public function getNoticesAsArrayShouldAnswerEmptyArray() { + public function getNoticesAsArrayShouldAnswerEmptyArray() + { $panier = $this->fixture(Class_PanierNotice::class, ['id' => 5, 'notices' => ' ']); - $this->onLoaderOfModel(Class_Notice::class) - ->whenCalled('findAllBy') - ->never() - ->beStrict(); - $this->assertEquals([], $panier->getNoticesAsArray()); } } diff --git a/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php b/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php index b5ed39fcb3f38f989cecc702c478af96b6410ebd..68b5539e4b1137dec70afaf00d05012030ba5e21 100644 --- a/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php +++ b/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php @@ -121,13 +121,23 @@ class TemplatesAbonneShowUserCartAsAdminTest extends Admin_AbstractControllerTes class TemplatesAbonneSelectionsAsAbonneTest extends TemplatesAbonneSelectionsTestCase { - public function setUp(): void { + protected array $_storm_scopes = [Class_PanierNotice::class]; + + public function setUp(): void + { parent::setUp(); $this->dispatch('/opac/abonne/selections/id_profil/72'); } + /** @test */ + public function sqlLoadCartsShouldBeCalledOnlyOneTime() + { + $this->assertSqlCount("SELECT `notices`.* FROM `notices` WHERE (`notices`.`clef_alpha` IN ('COMBAT ORDINAIRE', 'BLACKSAD')) ORDER BY FIELD(`notices`.`clef_alpha`, 'COMBAT ORDINAIRE', 'BLACKSAD') ASC", 1); + } + + /** @test */ public function dispatchSelectionsShouldContainsCreerSelectionAnchor() { $this->assertXPathContentContains('//a[contains(@href, "/abonne/creer-selection")]','Créer'); @@ -604,11 +614,17 @@ abstract class TemplatesAbonneSelectionsOthersAsAdminTestCase $this->fixture(Class_Notice::class, ['id' => 123, - 'clef_alpha' => 'COMBAT ORDINAIRE']); + 'clef_alpha' => 'COMBAT ORDINAIRE', + 'unimarc' => (new Class_NoticeUnimarc_Fluent) + ->zoneWithChildren('200', ['a' => 'title combat']) + ->render()]); $this->fixture(Class_Notice::class, - ['id' => 123, - 'clef_alpha' => 'BLACKSAD']); + ['id' => 124, + 'clef_alpha' => 'BLACKSAD', + 'unimarc' => (new Class_NoticeUnimarc_Fluent) + ->zoneWithChildren('200', ['a' => 'title blacksad']) + ->render()]); $this->_mes_bd = $this->fixture(Class_PanierNotice::class, ['id' => 2,