From 5b1fe16e9e417282f5c977492181104d461aa042 Mon Sep 17 00:00:00 2001 From: ralf Date: Sat, 5 Nov 2022 09:12:24 +0100 Subject: [PATCH] New method Api\Accounts::isHuge() is used to NOT query members and (not yet working) disable the column in group-list --- admin/inc/class.admin_ui.inc.php | 19 ++++++++++++---- admin/templates/default/index.xet | 2 +- api/src/Accounts.php | 37 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/admin/inc/class.admin_ui.inc.php b/admin/inc/class.admin_ui.inc.php index b395244a78..11e7271fdd 100644 --- a/admin/inc/class.admin_ui.inc.php +++ b/admin/inc/class.admin_ui.inc.php @@ -437,8 +437,14 @@ class admin_ui /** * Callback for the nextmatch to get groups + * + * Does NOT set members for huge installations, but return "is_huge" === true in $rows. + * + * @param array &$query + * @param array|null &$rows on return rows plus boolean value for key "is_huge" === Accounts::isHuge() + * @return int total number of rows */ - public static function get_groups(&$query, &$rows) + public static function get_groups(array &$query, array &$rows=null) { $groups = $GLOBALS['egw']->accounts->search(array( 'type' => 'groups', @@ -463,7 +469,8 @@ class admin_ui $apps[] = $app; } - $rows = array(); + $rows = []; + $is_huge = $GLOBALS['egw']->accounts->isHuge(); foreach($groups as &$group) { $run_rights = $GLOBALS['egw']->acl->get_user_applications($group['account_id'], false, false); @@ -475,10 +482,14 @@ class admin_ui } } - $group['members'] = $GLOBALS['egw']->accounts->members($group['account_id'],true); + // do NOT set members for huge installations, but return "is_huge" === true in $rows + if (!$is_huge) + { + $group['members'] = $GLOBALS['egw']->accounts->members($group['account_id'],true); + } $rows[] = $group; } - + $rows['is_huge'] = $is_huge; return $GLOBALS['egw']->accounts->total; } diff --git a/admin/templates/default/index.xet b/admin/templates/default/index.xet index cb1c196642..607cc52cca 100644 --- a/admin/templates/default/index.xet +++ b/admin/templates/default/index.xet @@ -58,7 +58,7 @@ - + diff --git a/api/src/Accounts.php b/api/src/Accounts.php index b6a505d7bb..ac2e71f2cf 100644 --- a/api/src/Accounts.php +++ b/api/src/Accounts.php @@ -1513,6 +1513,43 @@ class Accounts Cache::setCache($this->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT); } + /** + * Number of accounts to consider an installation huge + */ + const HUGE_LIMIT = 500; + + /** + * Check if instance is huge, has more than self::HUGE_LIMIT=500 users + * + * Can be used to disable features not working well for a huge installation. + * + * @param int|null $set=null to set call with total number of accounts + * @return bool + */ + public function isHuge(int $total=null) + { + return true; + if (isset($total)) + { + $is_huge = $total > self::HUGE_LIMIT; + Cache::setInstance(__CLASS__, 'is_huge', $is_huge); + return $is_huge; + } + return Cache::getInstance(__CLASS__, 'is_huge', function() + { + $save_total = $this->total; // save and restore current total, to not have an unwanted side effect + $this->search([ + 'type' => 'accounts', + 'start' => 0, + 'offset' => 1, + 'active' => false, // as this is set by admin_ui::get_users() and therefore we only return the cached result + ]); + $total = $this->total; + $this->total = $save_total; + return $this->isHuge($total); + }); + } + /** * Internal functions not meant to use outside this class!!! */