summaryrefslogtreecommitdiff
path: root/app/Core/User/GroupSync.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2018-10-02 15:15:23 -0700
committerFrédéric Guillot <fred@kanboard.net>2018-10-02 15:15:23 -0700
commitc06a1108304eb31d15523fcd3caf78509eefd841 (patch)
tree768af86802bd5a4ec9c69768d761ee4f0cce52be /app/Core/User/GroupSync.php
parent5cce000f9560d52a7f2444f9f8b46c2a9e7750cf (diff)
Reduce number of SQL queries when doing groups sync
Diffstat (limited to 'app/Core/User/GroupSync.php')
-rw-r--r--app/Core/User/GroupSync.php27
1 files changed, 12 insertions, 15 deletions
diff --git a/app/Core/User/GroupSync.php b/app/Core/User/GroupSync.php
index d0bb647b..0e2a87fe 100644
--- a/app/Core/User/GroupSync.php
+++ b/app/Core/User/GroupSync.php
@@ -16,8 +16,8 @@ class GroupSync extends Base
* Synchronize group membership
*
* @access public
- * @param integer $userId
- * @param array $externalGroupIds
+ * @param integer $userId
+ * @param string[] $externalGroupIds
*/
public function synchronize($userId, array $externalGroupIds)
{
@@ -30,21 +30,18 @@ class GroupSync extends Base
* Add missing groups to the user
*
* @access protected
- * @param integer $userId
- * @param array $userGroups
- * @param array $externalGroupIds
+ * @param integer $userId
+ * @param array $userGroups
+ * @param string[] $externalGroupIds
*/
protected function addGroups($userId, array $userGroups, array $externalGroupIds)
{
$userGroupIds = array_column($userGroups, 'external_id', 'external_id');
+ $externalGroups = $this->groupModel->getByExternalIds($externalGroupIds);
- foreach ($externalGroupIds as $externalGroupId) {
- if (! isset($userGroupIds[$externalGroupId])) {
- $group = $this->groupModel->getByExternalId($externalGroupId);
-
- if (! empty($group)) {
- $this->groupMemberModel->addUser($group['id'], $userId);
- }
+ foreach ($externalGroups as $externalGroup) {
+ if (! isset($userGroupIds[$externalGroup['external_id']])) {
+ $this->groupMemberModel->addUser($externalGroup['id'], $userId);
}
}
}
@@ -53,9 +50,9 @@ class GroupSync extends Base
* Remove groups from the user
*
* @access protected
- * @param integer $userId
- * @param array $userGroups
- * @param array $externalGroupIds
+ * @param integer $userId
+ * @param array $userGroups
+ * @param string[] $externalGroupIds
*/
protected function removeGroups($userId, array $userGroups, array $externalGroupIds)
{