From 0b4addaca7d0b6746fa31f773af98b58f86e47ec Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Thu, 20 May 2021 15:49:00 +0200 Subject: [PATCH] dev #135950 Performances - limit same head key record loading - digital ressources : do not try to load more than once inexisting doc types --- library/Class/DigitalResource.php | 8 +++++++- library/Class/Notice.php | 19 +++++++++++++------ library/Class/Notice/Facettes.php | 2 +- .../controllers/NoticeAjaxControllerTest.php | 6 ++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/library/Class/DigitalResource.php b/library/Class/DigitalResource.php index af4bfad3897..3694e4ef14e 100644 --- a/library/Class/DigitalResource.php +++ b/library/Class/DigitalResource.php @@ -463,9 +463,15 @@ class Class_DigitalResource_Wrapper { class Class_DigitalResource_ConfigProvider { + protected static $_known_classes = []; + public function getConfig($digital_resource, $class_name, $plugin) { - if(!@class_exists($class_name)) + if (!isset(static::$_known_classes[$class_name])) + static::$_known_classes[$class_name] = @class_exists($class_name); + + if (!static::$_known_classes[$class_name]) return null; + return new $class_name(new Class_DigitalResource_Wrapper($digital_resource, $plugin)); } } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index fbe2785c6e5..de71d613a7e 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -109,9 +109,10 @@ class NoticeLoader extends Storm_Model_Loader { } - public function getAllNoticesByClefChapeau($clef) { - return Class_Notice::findAllBy(['clef_chapeau' => $clef, - 'order' => 'tome_alpha desc']); + public function getAllNoticesByClefChapeau($clef, $conditions) { + return Class_Notice::findAllBy(array_merge($conditions, + ['clef_chapeau' => $clef, + 'order' => 'tome_alpha desc'])); } @@ -216,7 +217,8 @@ class Class_Notice extends Storm_Model_Abstract { $_first_exemplaire, $_data_map, $_collation, - $_main_author_cache; + $_main_author_cache, + $_same_serie_records; protected $_default_attribute_values = ['type_doc' => 0, 'annee' => null, @@ -803,10 +805,15 @@ class Class_Notice extends Storm_Model_Abstract { public function getNoticesMemeSeries() { + if (isset($this->_same_serie_records)) + return $this->_same_serie_records; + if (!$this->hasSerie()) - return []; + return $this->_same_serie_records = []; - return $this->getLoader()->getAllNoticesByClefChapeau($this->getClefChapeau()); + return $this->_same_serie_records = $this->getLoader() + ->getAllNoticesByClefChapeau($this->getClefChapeau(), + ['limit' => 20]); } diff --git a/library/Class/Notice/Facettes.php b/library/Class/Notice/Facettes.php index eb9ea2a6b30..e476cfee5f1 100644 --- a/library/Class/Notice/Facettes.php +++ b/library/Class/Notice/Facettes.php @@ -89,7 +89,7 @@ class Class_Notice_Facettes { return $this->_record->getExemplaires(); $clef_chapeau = Class_Indexation::getInstance()->codeAlphaTitre($this->_record->getTitrePrincipal()); - $records = Class_Notice::getAllNoticesByClefChapeau($clef_chapeau); + $records = Class_Notice::getAllNoticesByClefChapeau($clef_chapeau, ['limit' => 20]); $record_ids = (new Storm_Model_Collection($records))->collect('id'); if ($record_ids->isEmpty()) diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 09f176d8cda..f045df6c123 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1332,7 +1332,8 @@ class NoticeAjaxControllerDVDSeriesTest extends AbstractControllerTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') ->whenCalled('findAllBy') ->with(['clef_chapeau' => 'OZ', - 'order' => 'tome_alpha desc']) + 'order' => 'tome_alpha desc', + 'limit' => 20]) ->answers([$oz_season2, $oz_season3]); @@ -1415,7 +1416,8 @@ class NoticeAjaxControllerPeriodiqueSerieTest extends NoticeAjaxControllerPeriod $this->onLoaderOfModel(Class_Notice::class) ->whenCalled('findAllBy') ->with(['clef_chapeau' => 'FAKIR', - 'order' => 'tome_alpha desc']) + 'order' => 'tome_alpha desc', + 'limit' => 20]) ->answers([$this->_fakir_56, $this->_fakir_57]); $this->dispatch('/noticeajax/series/id_notice/234'); -- GitLab