Skip to content
Snippets Groups Projects
Commit 13262eef authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #128992 : enlarge your perfs

parent 03bdc69e
Branches
Tags
2 merge requests!3891Hotline,!3884hotline #128992 : enlarge your perfs
Pipeline #12628 passed with stage
in 52 minutes and 54 seconds
Showing
with 291 additions and 143 deletions
- ticket #128992 : Amélioration des performances
\ No newline at end of file
......@@ -20,6 +20,7 @@
*/
class AvisNoticeLoader extends Storm_Model_Loader {
protected $_by_work_cache = [];
protected function _addCatalogueConditions($preferences, &$params) {
// voir fonction Class_Catalogue::getReguetes
......@@ -241,6 +242,16 @@ class AvisNoticeLoader extends Storm_Model_Loader {
? Class_AvisNotice::countBy(['source_actor_id' => $member->getActorId()])
: 0;
}
public function findAllByWork($work) {
if (isset($this->_by_work_cache[$work]))
return $this->_by_work_cache[$work];
return $this->_by_work_cache[$work] = $work
? Class_AvisNotice::findAllBy(['clef_oeuvre' => $work])
: [];
}
}
......
......@@ -33,11 +33,21 @@ class BibLoader extends Storm_Model_Loader {
protected
$_all_labels_cache,
$_all_sorted_by_label_cache,
$_opening_on_date_cache = [],
$_portail;
public function findAllSortedByLabel() {
if (isset($this->_all_sorted_by_label_cache))
return $this->_all_sorted_by_label_cache;
return $this->_all_sorted_by_label_cache = Class_Bib::findAllBy(['order' => 'libelle']);
}
public function findAllWithPortail() {
$all_bibs = Class_Bib::findAllBy(['order' => 'libelle']);
$all_bibs = Class_Bib::findAllSortedByLabel();
array_unshift($all_bibs, $this->getPortail());
return $all_bibs;
}
......@@ -60,19 +70,15 @@ class BibLoader extends Storm_Model_Loader {
public function findAllRedmineEnabled() {
return (new Storm_Model_Collection(Class_Bib::findAllBy(['order' => 'libelle'])))
return (new Storm_Model_Collection(Class_Bib::findAllSortedByLabel()))
->select('isRedmineEnabled')
->getArrayCopy();
}
public function getUserFriendlyBibs() {
$all_bibs = Class_Bib::getLoader()->findAllBy(['order' => 'libelle']);
$bibs_as_array = [];
foreach($all_bibs as $bib) {
$bibs_as_array[$bib->getId()] = $bib->getLabel();
}
return $bibs_as_array;
$all_bibs = Class_Bib::findAllSortedByLabel();
return Class_Bib::byIdLabels($all_bibs);
}
......@@ -84,15 +90,12 @@ class BibLoader extends Storm_Model_Loader {
public function getBibsWithMail() {
$all_bibs = Class_Bib::findAll();
$all_bibs = array_filter($all_bibs, function($bib) {return $bib->hasMail() ? $bib->getLibelle(): '';});
$libelles = [];
foreach($all_bibs as $bib) {
$libelles[$bib->getId()] = $bib->getLibelle();
}
asort($libelles);
return $libelles;
$all_bibs = array_filter(Class_Bib::findAllSortedByLabel(),
function($bib)
{
return $bib->hasMail();
});
return Class_Bib::byIdLabels($all_bibs);
}
......@@ -218,6 +221,49 @@ class BibLoader extends Storm_Model_Loader {
return Class_Bib::findAllBy(['visibilite' => Class_Bib::V_DATA,
'order' => 'libelle']);
}
public function openingOnDateOf($library, $time, $used_for) {
if (!$library)
return;
$id = $library->getId();
$day = date('Y-m-d', $time);
$key = $id . $day . $used_for;
if (array_key_exists($key, $this->_opening_on_date_cache))
return $this->_opening_on_date_cache[$key];
if (($used_for !== Class_Ouverture::USED_FOR_DRIVE)
&& $library->hasHoraire())
return $this->_opening_on_date_cache[$key] = null;
if ($ouverture = Class_Ouverture::findFirstBy(['jour' => $day,
'id_site' => $id,
'used_for' => $used_for]))
return $this->_opening_on_date_cache[$key] = $ouverture;
if ($library->isClosedOnHolidays() && Class_Date_Holiday::isHoliday($time))
return $this->_opening_on_date_cache[$key] = null;
$openings = new Storm_Model_Collection(Class_Ouverture::findAllByLibraryAndUsage($id, $used_for));
$day_of_week = Class_Date::dayOfWeek($time);
$blessed = $openings->select('hasValidityRange')
->detect(
function($o) use ($time, $day_of_week) {
return $o->isValidOnDate($time) && ($o->getJourSemaine() == $day_of_week);
});
if ($blessed)
return $this->_opening_on_date_cache[$key] = $blessed;
return $this->_opening_on_date_cache[$key] =
$openings->reject('hasValidityRange')
->detect(function($o) use ($day_of_week)
{
return $o->getJourSemaine() == $day_of_week;
});
}
}
......@@ -984,48 +1030,7 @@ class Class_Bib extends Storm_Model_Abstract {
public function getOuvertureOnDate($time, $used_for = Class_Ouverture::USED_FOR_LIBRARY) {
if ($used_for !== Class_Ouverture::USED_FOR_DRIVE && $this->hasHoraire())
return null;
if ($ouverture = Class_Ouverture::findFirstBy(['jour' => date('Y-m-d', $time),
'id_site' => $this->getId(),
'used_for' => $used_for]))
return $ouverture;
if ($this->isClosedOnHolidays() && Class_Date_Holiday::isHoliday($time))
return null;
$day_of_week = Class_Date::dayOfWeek($time);
$openings = new Storm_Model_Collection(
Class_Ouverture::findAllBy
(
[
'id_site' => $this->getId(),
'used_for'=> $used_for,
'order' => [
'jour',
'validity_end desc',
'validity_start desc',
'jour_semaine',
'debut_matin'
],
]
)
);
$blessed = $openings->select('hasValidityRange')
->detect(
function($o) use ($time, $day_of_week) {
return $o->isValidOnDate($time) && ($o->getJourSemaine() == $day_of_week);
});
return $blessed
? $blessed
: $openings->reject('hasValidityRange')
->detect(
function($o) use ($day_of_week) {
return $o->getJourSemaine() == $day_of_week;
});
return $this->getLoader()->openingOnDateOf($this, $time, $used_for);
}
......
......@@ -25,23 +25,30 @@ class CodifAuteurLoader extends Storm_Model_Loader {
RECORDS_LOAD_LIMIT = 100,
AUTHORS_FETCH_BIO_LIMIT = 50;
protected
$_by_alpha_cache = [],
$_by_fullname_cache = [];
public function findWithFullName($author) {
if(!$author)
return null;
if (isset($this->_by_fullname_cache[$author]))
return $this->_by_fullname_cache[$author];
$indexation = new Class_Indexation();
$alpha_author = $indexation->alphaMaj($author);
if(1 == count(($names = explode(' ', $author))))
return Class_CodifAuteur::findByCodeAlpha($alpha_author);
return $this->_by_fullname_cache[$author] = Class_CodifAuteur::findByCodeAlpha($alpha_author);
if(2 < count($names))
return Class_CodifAuteur::findFirstBy(['libelle' => $alpha_author]);
return $this->_by_fullname_cache[$author] = Class_CodifAuteur::findFirstBy(['libelle' => $alpha_author]);
return ($found = Class_CodifAuteur::findByLastNameFirstName($names[0], $names[1]))
? $found
: Class_CodifAuteur::findByLastNameFirstName($names[1], $names[0]);
return $this->_by_fullname_cache[$author] =
(($found = Class_CodifAuteur::findByLastNameFirstName($names[0], $names[1]))
? $found
: Class_CodifAuteur::findByLastNameFirstName($names[1], $names[0]));
}
......@@ -71,8 +78,11 @@ class CodifAuteurLoader extends Storm_Model_Loader {
public function findByCodeAlpha($code_alpha) {
return Class_CodifAuteur::findFirstBy(
['where' => "MATCH(formes) AGAINST('" . $code_alpha . "' IN BOOLEAN MODE)"]);
if (isset($this->_by_alpha_cache[$code_alpha]))
return $this->_by_alpha_cache[$code_alpha];
return $this->_by_alpha_cache[$code_alpha] =
Class_CodifAuteur::findFirstBy(['where' => "MATCH(formes) AGAINST('" . $code_alpha . "' IN BOOLEAN MODE)"]);
}
......
......@@ -20,6 +20,23 @@
*/
class Class_CodifLangueLoader extends Storm_Model_Loader {
protected $_id_without_match_cache = [];
public function find($id) {
if (in_array($id, $this->_id_without_match_cache))
return null;
if (!$model = parent::find($id))
$this->_id_without_match_cache[] = $id;
return $model;
}
}
class Class_CodifLangue extends Storm_Model_Abstract {
use Trait_Facetable;
......@@ -27,7 +44,8 @@ class Class_CodifLangue extends Storm_Model_Abstract {
protected
$_table_name = 'codif_langue',
$_table_primary = 'id_langue';
$_table_primary = 'id_langue',
$_loader_class = 'Class_CodifLangueLoader';
/**
......
......@@ -327,13 +327,9 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract {
public function getPanier() {
$panier = null;
$id_panier = $this->getParam('id_panier','');
if ($id_user=$this->getParam('id_user'))
$panier = Class_PanierNotice::findFirstBy(['id_user' => $id_user,
'id' => $id_panier]);
return $panier ? $panier : Class_PanierNotice::find($id_panier);
return ($id_panier = $this->getParam('id_panier'))
? Class_PanierNotice::find($id_panier)
: null;
}
......
......@@ -55,6 +55,9 @@ class CustomFieldsLoader extends Storm_Model_Loader {
public function findTypeForCustomFieldId($id) {
if (!$id = (int)$id)
return '';
return ($cf = Class_CustomField::find($id))
? $cf->getFieldType()
: '';
......
......@@ -127,12 +127,12 @@ class Class_CustomField_ModelValues {
public function save() {
$values = $this->getFieldValues();
foreach($values as $value) {
foreach($this->getFieldValues() as $value) {
$inner_value = $value->getValue();
empty($inner_value) ? $value->delete() : $value->save();
}
Class_CustomField_Value::resetByInstanceCache($this->_customized_model);
return $this;
}
}
?>
......@@ -20,6 +20,8 @@
*/
class Class_CustomField_ValueLoader extends Storm_Model_Loader {
protected $_by_instance_cache = [];
public function findOrCreate($model_id, $custom_field_id) {
$instance = Class_CustomField_Value::findFirstBy(['model_id' => $model_id,
'custom_field_id' => $custom_field_id]);
......@@ -32,16 +34,37 @@ class Class_CustomField_ValueLoader extends Storm_Model_Loader {
public function findAllByInstance($instance) {
if (!$instance
|| (!$model = Class_CustomField_Model::getModel(get_class($instance)))
|| (!$fields = $model->getFields()))
if (!$instance)
return [];
$key = $this->_instanceCacheKey($instance);
if (isset($this->_by_instance_cache[$key]))
return $this->_by_instance_cache[$key];
if ((!$model = Class_CustomField_Model::getModel(get_class($instance)))
|| (!$fields = $model->getFields()))
return $this->_by_instance_cache[$key] = [];
$field_ids = array_map(function($f) {return $f->getId();},
$fields);
return Class_CustomField_Value::findAllBy(['model_id' => $instance->getId(),
'custom_field_id' => $field_ids]);
return $this->_by_instance_cache[$key] =
Class_CustomField_Value::findAllBy(['model_id' => $instance->getId(),
'custom_field_id' => $field_ids]);
}
/** @category testing */
public function resetByInstanceCache($instance) {
if ($instance)
unset($this->_by_instance_cache[$this->_instanceCacheKey($instance)]);
return $this;
}
protected function _instanceCacheKey($instance) {
return get_class($instance) . $instance->getId();
}
......
......@@ -20,6 +20,8 @@
*/
class Class_LieuLoader extends Storm_Model_Loader {
protected $_labels_by_ids_cache;
public function newWith($library) {
$location = Class_Lieu::newInstance();
$location->updateAttributes(['libelle' => $library->getLibelle(),
......@@ -33,14 +35,20 @@ class Class_LieuLoader extends Storm_Model_Loader {
public function getAllLibelles() {
if (isset($this->_labels_by_ids_cache))
return $this->_labels_by_ids_cache;
$labels = [];
foreach(Class_Lieu::findAllBy(['order' => 'libelle']) as $location)
$labels[$location->getId()] = $location->getLibelle();
return $labels;
return $this->_labels_by_ids_cache = $labels;
}
}
class Class_Lieu extends Storm_Model_Abstract {
use Trait_Translator;
......
......@@ -19,9 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* example print template for agenda
/**
example print template for agenda
<style type="text/css">@page {margin: 0;}
</style>
......@@ -30,21 +29,27 @@
dates: {debut}- {fin}<br />
{description}</div>
]}</div>
*/
class Class_ModeleFusionLoader extends Storm_Model_Loader {
use Trait_Translator;
protected
$_by_strategy_profil_cache = [],
$_by_strategy_cache = [];
public function get($name) {
return $this->findFirstBy(['nom' => $name]);
}
public function getFusionForStrategy($strategy) {
return Class_ModeleFusion::findFirstBy(['type' => $strategy,
'profil_ids' => '']);
if (isset($this->_by_strategy_cache[$strategy]))
return $this->_by_strategy_cache[$strategy];
return $this->_by_strategy_cache[$strategy] =
Class_ModeleFusion::findFirstBy(['type' => $strategy, 'profil_ids' => '']);
}
......@@ -80,18 +85,19 @@ class Class_ModeleFusionLoader extends Storm_Model_Loader {
}
public function getFusionForStrategyAndProfil($strategy,$id_profil) {
public function getFusionForStrategyAndProfil($strategy, $id_profil) {
$key = $strategy . $id_profil;
if (isset($this->_by_strategy_profil_cache[$key]))
return $this->_by_strategy_profil_cache[$key];
$models = array_filter(
Class_ModeleFusion::findAllBy(['type' => $strategy]),
Class_ModeleFusion::findAllBy(['type' => $strategy,
'profil_ids not' => '']),
function($model) use ($id_profil) {
if (!$ids=$model->getProfilIds())
return false;
if (in_array($id_profil,explode(';',$ids)))
return $model;
return in_array($id_profil, explode(';', $model->getProfilIds()));
});
return reset($models);
return $this->_by_strategy_profil_cache[$key] = reset($models);
}
......
......@@ -288,10 +288,7 @@ class Class_Notice extends Storm_Model_Abstract {
public function getLocalAvis() {
if (!isset($this->_local_avis))
$this->_local_avis = Class_AvisNotice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()]);
return $this->_local_avis;
return Class_AvisNotice::findAllByWork($this->getClefOeuvre());
}
......@@ -1418,9 +1415,11 @@ class Class_Notice extends Storm_Model_Abstract {
public function getLanguages() {
return ($codes = $this->getLangueCodes())
? Class_CodifLangue::findAllBy(['id_langue' => $codes])
: [];
return array_filter(array_map(function($code)
{
return Class_CodifLangue::find($code);
},
$this->getLangueCodes()));
}
......
......@@ -25,6 +25,9 @@ class OuvertureLoader extends Storm_Model_Loader {
CLOSED_VALUE = '00:00',
CLOSED_VALUE_SQL = '00:00:00';
protected $_by_library_usage_cache = [];
public function compare($a, $b) {
if ($a->getJourSemaine() && $b->getJourSemaine() && $a->getJourSemaine() > $b->getJourSemaine())
return 1;
......@@ -92,6 +95,22 @@ class OuvertureLoader extends Storm_Model_Loader {
'used_for' => Class_Ouverture::USED_FOR_DRIVE])
: false;
}
public function findAllByLibraryAndUsage($library_id, $used_for) {
$key = $library_id . $used_for;
if (isset($this->_by_library_usage_cache[$key]))
return $this->_by_library_usage_cache[$key];
return $this->_by_library_usage_cache[$key] =
Class_Ouverture::findAllBy(['id_site' => $library_id,
'used_for' => $used_for,
'order' => ['jour',
'validity_end desc',
'validity_start desc',
'jour_semaine',
'debut_matin']]);
}
}
......
......@@ -23,6 +23,9 @@
class PanierNoticeLoader extends Storm_Model_Loader {
use Trait_Translator, Trait_TimeSource;
protected $_by_label_and_user_cache = [];
public function newForUser($user) {
return
(new Class_PanierNotice())
......@@ -99,7 +102,7 @@ class PanierNoticeLoader extends Storm_Model_Loader {
}
public function findAllBelongsToIdUser() {
public function findAllBelongsToIdUser() {
$select = $this
->getTable()
->select('notices_paniers.*')
......@@ -112,8 +115,24 @@ class PanierNoticeLoader extends Storm_Model_Loader {
return $this->findAll($select);
}
public function findAllUserIds() {
return Zend_Registry::get('sql')->fetchAllByColumn('select distinct(id_user) as id from notices_paniers');
public function findAllUserIds() {
return Zend_Registry::get('sql')
->fetchAllByColumn('select distinct(id_user) as id from notices_paniers');
}
public function findByLabelAndUser($label, $user) {
if (!$label || !$user)
return;
$key = $label . $user->getId();
if (array_key_exists($key, $this->_by_label_and_user_cache))
return $this->_by_label_and_user_cache[$key];
return $this->_by_label_and_user_cache[$key] =
Class_PanierNotice::findFirstBy(['libelle' => $label,
'id_user' => $user->getId()]);
}
}
......
......@@ -20,7 +20,10 @@
*/
class ProfilLoader extends Storm_Model_Loader {
protected $_root;
protected
$_root,
$_by_controller_action_cache = [];
public function getProfilsByBib($id_zone, $id_bib) {
$profils = Class_Profil::findAllByZoneAndBib($id_zone, $id_bib);
......@@ -126,11 +129,16 @@ class ProfilLoader extends Storm_Model_Loader {
public function findInControllerActionOf($request) {
$key = $request->getControllerName() . $request->getActionName();
if (isset($this->_by_controller_action_cache[$key]))
return $this->_by_controller_action_cache[$key];
if (!$profil = Class_Profil::findFirstBy(['rewrite_url' => $request->getControllerName()]))
return null;
return $this->_by_controller_action_cache[$key] = null;
return ($child = Class_Profil::findFirstBy(['rewrite_url' => $request->getActionName(),
'parent_id' => $profil->getId()]))
return $this->_by_controller_action_cache[$key] =
($child = Class_Profil::findFirstBy(['rewrite_url' => $request->getActionName(),
'parent_id' => $profil->getId()]))
? $child
: $profil;
}
......
......@@ -20,6 +20,8 @@
*/
class SessionActivityLoader extends Storm_Model_Loader {
protected $_by_article_cache = [];
public function findAllAvailable($user) {
if (!$user)
return [];
......@@ -76,9 +78,15 @@ class SessionActivityLoader extends Storm_Model_Loader {
public function findByArticle($article) {
return $article
? Class_SessionActivity::findFirstBy(['article_id' => $article->getId()])
: null;
if (!$article)
return;
$key = $article->getId();
if (array_key_exists($key, $this->_by_article_cache))
return $this->_by_article_cache[$key];
return $this->_by_article_cache[$key] =
Class_SessionActivity::findFirstBy(['article_id' => $article->getId()]);
}
......
......@@ -22,7 +22,9 @@
class TypeDocLoader extends Storm_Model_Loader {
use Trait_Translator;
protected $_all_instances;
protected
$_all_instances,
$_used_ids_cache;
public function __construct() {
$this->findAll();
......@@ -155,16 +157,11 @@ class TypeDocLoader extends Storm_Model_Loader {
public function findUsedTypeDocIds() {
if ( ! $table = Class_Notice::getTable())
return [];
if (isset($this->_used_ids_cache))
return $this->_used_ids_cache;
if ( ! $adapter = $table->getAdapter())
return [];
$rows = $adapter
->fetchAll('select distinct(type_doc) from notices');
return array_map(function($row){return $row['type_doc'];},
$rows);
return $this->_used_ids_cache = Zend_Registry::get('sql')
->fetchAllByColumn('select distinct(type_doc) from notices');
}
......
......@@ -35,9 +35,15 @@ class Class_User_Settings {
SEARCH_LAYOUT = 'search_layout',
SEARCH_PAGE_SIZE = 'search_page_size';
protected $_user, $_user_settings;
protected static
$_cache = [],
$_is_bookmark_library_cache,
$_is_bookmark_domains_cache;
protected static $_cache = [];
protected
$_user,
$_user_settings,
$_bookmarked_librairies_cache;
public static function newWith($user) {
......@@ -54,11 +60,16 @@ class Class_User_Settings {
public static function clearCache() {
static::$_cache = [];
static::$_is_bookmark_library_cache = null;
static::$_is_bookmark_domains_cache = null;
}
public static function isBookmarkLibraryReady() {
return
if (isset(static::$_is_bookmark_library_cache))
return static::$_is_bookmark_library_cache;
return static::$_is_bookmark_library_cache =
Class_AdminVar::isModuleEnabled('ENABLE_BOOKMARKABLE_LIBRARIES')
&&
(Class_Profil_ItemsSettings::current()->isItemAnnexDisplay()
......@@ -68,7 +79,10 @@ class Class_User_Settings {
public static function isBookmarkDomainsReady() {
return Class_Catalogue::hasViewableDomain();
if (isset(static::$_is_bookmark_domains_cache))
return static::$_is_bookmark_domains_cache;
return static::$_is_bookmark_domains_cache = Class_Catalogue::hasViewableDomain();
}
......@@ -141,18 +155,22 @@ class Class_User_Settings {
public function getBookmarkedLibraries() {
if (isset($this->_bookmarked_librairies_cache))
return $this->_bookmarked_librairies_cache;
if (!static::isBookmarkLibraryReady())
return $this->_clearBookmarkedLibraries();
return $this->_bookmarked_librairies_cache = $this->_clearBookmarkedLibraries();
if (!$value = $this->get(self::BOOKMARKED_LIBRARIES))
return $this->_initDefaultLibrary();
return $this->_bookmarked_librairies_cache = $this->_initDefaultLibrary();
if (!$storm_ids = $this->_getStormIds($value))
return [];
return $this->_bookmarked_librairies_cache = [];
return Class_Profil_ItemsSettings::current()->isItemAnnexDisplay()
? Class_CodifAnnexe::findAllBy(['id_annexe' => $storm_ids])
: Class_Bib::findAllBy(['id_site' => $storm_ids]);
return $this->_bookmarked_librairies_cache =
(Class_Profil_ItemsSettings::current()->isItemAnnexDisplay()
? Class_CodifAnnexe::findAllBy(['id_annexe' => $storm_ids])
: Class_Bib::findAllBy(['id_site' => $storm_ids]));
}
......
......@@ -22,19 +22,18 @@
class ZendAfi_View_Helper_Filters_Element_Place extends ZendAfi_View_Helper_Filters_Element {
protected $_elements;
public function __construct($custom_field_id = null) {
$this->_custom_field_id = 'place';
}
public function elements() {
$elements = [];
$labels = Class_Lieu::getLoader()->getAllLibelles();
foreach ($labels as $id => $label) {
$elements[$id] = $label;
}
if (isset($this->_elements))
return $this->_elements;
return $elements;
return $this->_elements = Class_Lieu::getAllLibelles();
}
}
......@@ -95,8 +95,8 @@ class Intonation_Library_Selection extends Class_Entity {
if (isset(static::$_selections_cache[$title]))
return static::$_selections_cache[$title];
return static::$_selections_cache[$title] = Class_PanierNotice::findFirstBy(['libelle' => $title,
'id_user' => $user->getId()]);
return static::$_selections_cache[$title]
= Class_PanierNotice::findByLabelAndUser($title, $user);
}
......
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