From 78f3f68127914ade4bf80cb1d9f4842a80e85601 Mon Sep 17 00:00:00 2001 From: iglocska Date: Mon, 11 Nov 2019 08:11:36 +0100 Subject: [PATCH] chg: [internal] Sharing group loader was grabbing organisations one by one, refactored - simply fetch all org objects for the ACL checks in one shot instead of doing it on demand - has no real performance impact even on large sharing instances - reduces the number of queries greatly making debugging easier --- app/Model/SharingGroup.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/app/Model/SharingGroup.php b/app/Model/SharingGroup.php index 113740579..89c51a1aa 100644 --- a/app/Model/SharingGroup.php +++ b/app/Model/SharingGroup.php @@ -181,14 +181,17 @@ class SharingGroup extends AppModel 'fields' => $fieldsSharingGroup[$permissionTree]['fields'], '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']) - )); + if (empty($this->__sgoCache)) { + $temp = $this->Organisation->find('all', array( + 'recursive' => -1, + 'fields' => $fieldsOrg + )); + $this->__sgoCache = array(); + foreach ($temp as $o) { + $this->__sgoCache[$o['Organisation']['id']] = $o; } + } + foreach ($sgs as &$sg) { if(isset($this->__sgoCache[$sg['SharingGroup']['org_id']]['Organisation'])) { $sg['Organisation'] = $this->__sgoCache[$sg['SharingGroup']['org_id']]['Organisation']; } else { @@ -196,13 +199,6 @@ class SharingGroup extends AppModel } if (!empty($sg['SharingGroupOrg'])) { 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']) - )); - } if (!empty($this->__sgoCache[$sgo['org_id']]['Organisation'])) { $sgo['Organisation'] = $this->__sgoCache[$sgo['org_id']]['Organisation']; }