new: [internal] Added caching to the sharing group organisations

pull/3729/head
iglocska 2018-10-01 14:49:12 +02:00
parent 0fabffd5ed
commit 1a5f764048
1 changed files with 23 additions and 4 deletions

View File

@ -53,6 +53,8 @@ class SharingGroup extends AppModel
) )
); );
private $__sgoCache = array();
public function beforeValidate($options = array()) public function beforeValidate($options = array())
{ {
@ -163,10 +165,7 @@ class SharingGroup extends AppModel
array( array(
'fields' => array('SharingGroup.*'), 'fields' => array('SharingGroup.*'),
'contain' => array( 'contain' => array(
'Organisation' => array('fields' => $fieldsOrg), 'SharingGroupOrg',
'SharingGroupOrg' => array(
'Organisation' => array('fields' => $fieldsOrg),
),
'SharingGroupServer' => array( 'SharingGroupServer' => array(
'Server' => array('fields' => $fieldsServer), 'Server' => array('fields' => $fieldsServer),
) )
@ -179,6 +178,26 @@ class SharingGroup extends AppModel
'fields' => $fieldsSharingGroup[$permissionTree]['fields'], 'fields' => $fieldsSharingGroup[$permissionTree]['fields'],
'order' => 'SharingGroup.name ASC' 'order' => 'SharingGroup.name ASC'
)); ));
foreach ($sgs as &$sg) {
if (!isset($this->__sgoCache[$sg['SharingGroup']['org_id']])) {
$this->__sgoCache[$sg['SharingGroup']['org_id']] = $this->Organisation->find('first', array(
'recursive' => -1,
'fields' => $fieldsOrg,
'conditions' => array('id' => $sg['SharingGroup']['org_id'])
));
}
$sg['Organisation'] = $this->__sgoCache[$sg['SharingGroup']['org_id']];
foreach ($sg['SharingGroupOrg'] as &$sgo) {
if (!isset($this->__sgoCache[$sgo['org_id']])) {
$this->__sgoCache[$sgo['org_id']] = $this->Organisation->find('first', array(
'recursive' => -1,
'fields' => $fieldsOrg,
'conditions' => array('id' => $sgo['org_id'])
));
}
$sgo['Organisation'] = $this->__sgoCache[$sgo['org_id']];
}
}
return $sgs; return $sgs;
} elseif ($scope == 'name') { } elseif ($scope == 'name') {
$sgs = $this->find('list', array( $sgs = $this->find('list', array(