Commit 28483c56 authored by Patrick Barroca's avatar Patrick Barroca 😠
Browse files

hotline#105091 : Performance : Issue fixed in dynamic library groups management

parent c93ec337
Pipeline #9313 canceled with stage
in 2 minutes and 3 seconds
- ticket #105091 : Performance : Correction de la perte de performance suite à la livraison des nouveaux groupes dynamiques
\ No newline at end of file
......@@ -22,6 +22,17 @@
class UserGroupLoader extends Storm_Model_Loader {
use Trait_MemoryCleaner;
protected $_dynamics_of_user_cache = [];
public function save($model) {
$result = parent::save($model);
if ($model->isDynamic())
$this->_dynamics_of_user_cache = [];
return $result;
}
public function getUsersIdsOf($group) {
$ids = [];
......@@ -99,6 +110,23 @@ class UserGroupLoader extends Storm_Model_Loader {
public function findAllDynamics() {
return Class_UserGroup::findAllBy(['group_type' => Class_UserGroup::TYPE_DYNAMIC]);
}
public function findAllDynamicsOf($user) {
if ($user->isNew())
return $this->_realFindAllDynamicsOf($user);
$key = $user->getId();
return array_key_exists($key, $this->_dynamics_of_user_cache)
? $this->_dynamics_of_user_cache[$key]
: ($this->_dynamics_of_user_cache[$key] = $this->_realFindAllDynamicsOf($user));
}
protected function _realFindAllDynamicsOf($user) {
return array_filter(Class_UserGroup::findAllDynamics(),
function($group) use($user) { return $group->hasUser($user); });
}
}
......
......@@ -827,8 +827,7 @@ class Class_Users extends Storm_Model_Abstract {
public function getDynamicUserGroups() {
return array_filter(Class_UserGroup::findAllDynamics(),
function($group) { return $group->hasUser($this); });
return Class_UserGroup::findAllDynamicsOf($this);
}
......
......@@ -28,6 +28,8 @@ abstract class AbstractAbonneControllerFicheTest extends AbstractControllerTestC
$this->fixture('Class_Bib', ['id' => 1]);
$this->fixture('Class_Bib', ['id' => 2]);
$this->onLoaderOfModel('Class_UserGroup');
$this->marcus = $this->fixture('Class_Users',
['id' => 10,
'login' => 'MC',
......@@ -121,11 +123,18 @@ class AbonneControllerFicheAsAbonneTest extends AbstractAbonneControllerFicheTes
$this->assertXPathContentContains('//div[@class="abonneTitre"]//span[@data-name="last-name"]', 'Miller');
}
/** @test */
public function LoansHistoryShouldNotBeDisplayed() {
$this->assertNotXPathContentContains('//a', 'Voir mon historique de prêts');
}
// @see http://forge.afi-sa.fr/issues/105091
/** @test */
public function callToFindAllDynamicsShouldBeDoneOnlyOnce() {
$this->assertEquals(1, Class_UserGroup::methodCallCount('findAllDynamics'));
}
}
......
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