diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index 4d2b352d2..9e0ed3230 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -425,6 +425,12 @@ class UserRightsProfile extends UserRightsAddOnAPI UR_ACTION_BULK_DELETE => 'bd', ); + /** + * @var array $aUsersProfilesList Cache of users' profiles. Hash array of user ID => [profile ID => profile friendlyname, profile ID => profile friendlyname, ...] + * @since 2.7.10 3.0.4 3.1.1 3.2.0 N°6887 + */ + private $aUsersProfilesList = []; + // Installation: create the very first user public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') { @@ -654,8 +660,12 @@ class UserRightsProfile extends UserRightsAddOnAPI $sAction = self::$m_aActionCodes[$iActionCode]; $bStatus = null; + // Cache user's profiles + if(false === array_key_exists($iUser, $this->aUsersProfilesList)){ + $this->aUsersProfilesList[$iUser] = UserRights::ListProfiles($oUser); + } // Call the API of UserRights because it caches the list for us - foreach(UserRights::ListProfiles($oUser) as $iProfile => $oProfile) + foreach($this->aUsersProfilesList[$iUser] as $iProfile => $oProfile) { $bGrant = $this->GetProfileActionGrant($iProfile, $sClass, $sAction); if (!is_null($bGrant)) @@ -781,11 +791,16 @@ class UserRightsProfile extends UserRightsAddOnAPI // Note: this code is VERY close to the code of IsActionAllowed() $iUser = $oUser->GetKey(); + // Cache user's profiles + if(false === array_key_exists($iUser, $this->aUsersProfilesList)){ + $this->aUsersProfilesList[$iUser] = UserRights::ListProfiles($oUser); + } + // Note: The object set is ignored because it was interesting to optimize for huge data sets // and acceptable to consider only the root class of the object set $bStatus = null; // Call the API of UserRights because it caches the list for us - foreach(UserRights::ListProfiles($oUser) as $iProfile => $oProfile) + foreach($this->aUsersProfilesList[$iUser] as $iProfile => $oProfile) { $bGrant = $this->GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode); if (!is_null($bGrant))