From 95ec1c0b7030efbd6b38286189f9b93180baf611 Mon Sep 17 00:00:00 2001
From: Paul Mehrer
Date: Wed, 5 Feb 2025 18:13:15 +0100
Subject: [PATCH] tweak(Timetracker) performance improvement of container acl
filter
---
tine20/Timetracker/Model/TimesheetFilter.php | 22 +++++--------------
.../Tinebase/Controller/Record/Container.php | 8 +------
2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/tine20/Timetracker/Model/TimesheetFilter.php b/tine20/Timetracker/Model/TimesheetFilter.php
index c10ec9d553b..691bd310da0 100644
--- a/tine20/Timetracker/Model/TimesheetFilter.php
+++ b/tine20/Timetracker/Model/TimesheetFilter.php
@@ -113,13 +113,7 @@ protected function _appendAclSqlFilter($_select)
if (! $this->_isResolved) {
// get all timeaccounts user has required grants for
- $result = array();
- foreach ($this->_requiredGrants as $grant) {
- if ($grant != Timetracker_Model_TimeaccountGrants::BOOK_OWN) {
- $result = array_merge($result, Timetracker_Controller_Timeaccount::getInstance()->getRecordsByAcl($grant, TRUE));
- }
- }
- $this->_validTimeaccounts = array_unique($result);
+ $this->_validTimeaccounts = Timetracker_Controller_Timeaccount::getInstance()->getRecordsByAcl(array_filter($this->_requiredGrants, fn($grant) => $grant !== Timetracker_Model_TimeaccountGrants::BOOK_OWN), true);
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__
. ' valid timeaccounts' . print_r($this->_validTimeaccounts, TRUE) . ' for required grants: ' . print_r($this->_requiredGrants, TRUE));
$this->_isResolved = TRUE;
@@ -131,15 +125,11 @@ protected function _appendAclSqlFilter($_select)
$where = $db->quoteInto("$field IN (?)", empty($this->_validTimeaccounts) ? array('') : $this->_validTimeaccounts);
// get timeaccounts with *_OWN right
- $bookOwnTS = [];
- foreach ([
- Timetracker_Model_TimeaccountGrants::BOOK_OWN,
- Timetracker_Model_TimeaccountGrants::READ_OWN,
- Timetracker_Model_TimeaccountGrants::REQUEST_OWN,
- ] as $grant) {
- $bookOwnTS = array_merge($bookOwnTS, Timetracker_Controller_Timeaccount::getInstance()->getRecordsByAcl($grant, true));
- }
- $bookOwnTS = array_unique($bookOwnTS);
+ $bookOwnTS = Timetracker_Controller_Timeaccount::getInstance()->getRecordsByAcl([
+ Timetracker_Model_TimeaccountGrants::BOOK_OWN,
+ Timetracker_Model_TimeaccountGrants::READ_OWN,
+ Timetracker_Model_TimeaccountGrants::REQUEST_OWN,
+ ], true);
if (! empty($bookOwnTS)) {
$where .= ' OR (' . $db->quoteInto($field . ' IN (?)', $bookOwnTS)
. ' AND ' . $db->quoteInto($db->quoteIdentifier('account_id'). ' = ?', Tinebase_Core::getUser()->getId()) .')';
diff --git a/tine20/Tinebase/Controller/Record/Container.php b/tine20/Tinebase/Controller/Record/Container.php
index 22b3de7aae4..fa6ab178b8a 100644
--- a/tine20/Tinebase/Controller/Record/Container.php
+++ b/tine20/Tinebase/Controller/Record/Container.php
@@ -251,13 +251,7 @@ public function getRecordsByAcl($_grant, $_onlyIds = FALSE)
// NOTE: use id filter instead of container filter because of poor performance of container filter (setValue)
$filter->addFilter(new Tinebase_Model_Filter_Id('container_id', 'in', $containerIds));
- $result = $this->_backend->search($filter);
-
- if ($_onlyIds) {
- $result = $result->getArrayOfIds();
- }
-
- return $result;
+ return $this->_backend->search($filter, null, $_onlyIds ? Tinebase_Backend_Sql_Abstract::IDCOL : Tinebase_Backend_Sql_Abstract::ALLCOL);
}
/**