From 006c191a868310452a588e798603169cd92f55d3 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Thu, 10 Aug 2023 13:55:01 +0800 Subject: [PATCH] * Optimize execution drop-down speed. --- db/update18.6.sql | 2 ++ db/zentao.sql | 15 +++++++------- module/execution/control.php | 22 +++++++++++++++++++-- module/execution/model.php | 20 +++++++++++-------- module/program/model.php | 38 +++++++++++++++++------------------- 5 files changed, 60 insertions(+), 37 deletions(-) diff --git a/db/update18.6.sql b/db/update18.6.sql index 7757169b7d..af7f72e92f 100644 --- a/db/update18.6.sql +++ b/db/update18.6.sql @@ -41,3 +41,5 @@ CREATE INDEX deleted ON zt_bug (deleted); CREATE INDEX product_status_deleted ON zt_bug (product,status,deleted); UPDATE `zt_cron` SET `m` = '*/1' WHERE `command` in ('moduleName=mail&methodName=asyncSend', 'moduleName=webhook&methodName=asyncSend') and `type` = 'zentao'; + +ALTER TABLE `zt_project` ADD INDEX `type_order` (`type`, `order`); diff --git a/db/zentao.sql b/db/zentao.sql index 4733cf9f0e..2767be207d 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -1465,13 +1465,14 @@ CREATE TABLE IF NOT EXISTS `zt_project` ( `deleted` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE INDEX `parent` ON `zt_project` (`parent`); -CREATE INDEX `begin` ON `zt_project` (`begin`); -CREATE INDEX `end` ON `zt_project` (`end`); -CREATE INDEX `status` ON `zt_project` (`status`); -CREATE INDEX `acl` ON `zt_project` (`acl`); -CREATE INDEX `order` ON `zt_project` (`order`); -CREATE INDEX `project` ON `zt_project` (`project`); +CREATE INDEX `parent` ON `zt_project` (`parent`); +CREATE INDEX `begin` ON `zt_project` (`begin`); +CREATE INDEX `end` ON `zt_project` (`end`); +CREATE INDEX `status` ON `zt_project` (`status`); +CREATE INDEX `acl` ON `zt_project` (`acl`); +CREATE INDEX `order` ON `zt_project` (`order`); +CREATE INDEX `project` ON `zt_project` (`project`); +CREATE INDEX `type_order` ON `zt_project` (`type`, `order`); -- DROP TABLE IF EXISTS `zt_projectadmin`; CREATE TABLE IF NOT EXISTS `zt_projectadmin` ( diff --git a/module/execution/control.php b/module/execution/control.php index b20e1f7d0c..8238ca8be0 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -3854,7 +3854,8 @@ class execution extends control } $projects = $this->loadModel('program')->getProjectList(0, 'all', 0, 'order_asc', null, 0, 0, true); - $executionGroups = $this->dao->select('*')->from(TABLE_EXECUTION) + /* + $executionGroups = $this->dao->select('id,parent,project,grade,status,name,type,PM')->from(TABLE_EXECUTION) ->where('deleted')->eq(0) ->andWhere('multiple')->eq('1') ->andWhere('type')->in('sprint,stage,kanban') @@ -3862,6 +3863,23 @@ class execution extends control ->andWhere('project')->in(array_keys($projects)) ->orderBy('order_asc') ->fetchGroup('project', 'id'); + */ + + $childExecutions = $this->dao->select('id,parent,project,grade,status,name,type,PM')->from(TABLE_EXECUTION) + ->where('deleted')->eq(0) + ->andWhere('multiple')->eq('1') + ->andWhere('type')->in('sprint,stage,kanban') + ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->sprints)->fi() + ->andWhere('project')->in(array_keys($projects)) + ->orderBy('order_asc') + ->fetchAll('id'); + + $executionGroups = array(); + foreach($childExecutions as $executionID => $execution) + { + if(!isset($executionGroups[$execution->project])) $executionGroups[$execution->project] = array(); + $executionGroups[$execution->project][$executionID] = $execution; + } $teams = $this->dao->select('root,account')->from(TABLE_TEAM) ->where('root')->in($this->app->user->view->sprints) @@ -3883,7 +3901,7 @@ class execution extends control if($execution->grade == 1) $firstGradeExecs[$execution->id] = $execution->id; } - $executions = $this->execution->resetExecutionSorts($executions, $firstGradeExecs); + $executions = $this->execution->resetExecutionSorts($executions, $firstGradeExecs, $childExecutions); foreach($executions as $execution) { /* Only show leaf executions. */ diff --git a/module/execution/model.php b/module/execution/model.php index ef8ca22dd1..80c671a45f 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -6107,16 +6107,17 @@ class executionModel extends model * * @param array $executions * @param array $parentExecutions + * @param array $childExecutions * @access public * @return array */ - public function resetExecutionSorts($executions, $parentExecutions = array()) + public function resetExecutionSorts($executions, $parentExecutions = array(), $childExecutions = array()) { if(empty($executions)) return array(); if(empty($parentExecutions)) { $execution = current($executions); - $parentExecutions = $this->dao->select('*')->from(TABLE_EXECUTION) + $parentExecutions = $this->dao->select('id,parent,project,grade,status,name,type,PM')->from(TABLE_EXECUTION) ->where('parent')->eq($execution->project) ->andWhere('deleted')->eq('0') ->andWhere('type')->in('kanban,sprint,stage') @@ -6125,11 +6126,14 @@ class executionModel extends model ->fetchAll('id'); } - $childExecutions = $this->dao->select('*')->from(TABLE_EXECUTION) - ->where('deleted')->eq(0) - ->andWhere('parent')->in(array_keys($parentExecutions)) - ->orderBy('order_asc') - ->fetchGroup('parent', 'id'); + if(empty($childExecutions)) + { + $childExecutions = $this->dao->select('id,parent,project,grade,status,name,type,PM')->from(TABLE_EXECUTION) + ->where('deleted')->eq(0) + ->andWhere('parent')->in(array_keys($parentExecutions)) + ->orderBy('order_asc') + ->fetchGroup('parent', 'id'); + } $sortedExecutions = array(); foreach($parentExecutions as $executionID => $execution) @@ -6137,7 +6141,7 @@ class executionModel extends model if(!isset($sortedExecutions[$executionID]) and isset($executions[$executionID])) $sortedExecutions[$executionID] = $executions[$executionID]; $children = zget($childExecutions, $executionID, array()); - if(!empty($children)) $sortedExecutions += $this->resetExecutionSorts($executions, $children); + if(!empty($children)) $sortedExecutions += $this->resetExecutionSorts($executions, $children, $childExecutions); } return $sortedExecutions; } diff --git a/module/program/model.php b/module/program/model.php index 45ac9e7706..ee3140f09a 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -544,15 +544,13 @@ class programModel extends model if($browseType == 'bySearch' and $this->session->projectQuery == false) $this->session->set('projectQuery', ' 1 = 1'); } - $query = str_replace('`id`','t1.id', $this->session->projectQuery); - $projectList = $this->dao->select('DISTINCT t1.*')->from(TABLE_PROJECT)->alias('t1') - ->leftJoin(TABLE_TEAM)->alias('t2')->on('t1.id=t2.root') - ->leftJoin(TABLE_STAKEHOLDER)->alias('t3')->on('t1.id=t3.objectID') - ->where('t1.deleted')->eq('0') + $query = str_replace('`id`','t1.id', $this->session->projectQuery); + $stmt = $this->dao->select('DISTINCT t1.*')->from(TABLE_PROJECT)->alias('t1'); + if($this->cookie->involved || $involved) $stmt->leftJoin(TABLE_TEAM)->alias('t2')->on('t1.id=t2.root')->leftJoin(TABLE_STAKEHOLDER)->alias('t3')->on('t1.id=t3.objectID'); + $stmt->where('t1.deleted')->eq('0') ->andWhere('t1.vision')->eq($this->config->vision) ->beginIF($browseType == 'bysearch' and $query)->andWhere($query)->fi() ->andWhere('t1.type')->eq('project') - ->beginIF($this->cookie->involved or $involved)->andWhere('t2.type')->eq('project')->fi() ->beginIF(!in_array($browseType, array('all', 'undone', 'bysearch', 'review', 'unclosed'), true))->andWhere('t1.status')->eq($browseType)->fi() ->beginIF($browseType == 'undone' or $browseType == 'unclosed')->andWhere('t1.status')->in('wait,doing')->fi() ->beginIF($browseType == 'review') @@ -560,20 +558,20 @@ class programModel extends model ->andWhere('t1.reviewStatus')->eq('doing') ->fi() ->beginIF($path)->andWhere('t1.path')->like($path . '%')->fi() - ->beginIF(!$queryAll and !$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->projects)->fi() - ->beginIF($this->cookie->involved or $involved) - ->andWhere('t1.openedBy', true)->eq($this->app->user->account) - ->orWhere('t1.PM')->eq($this->app->user->account) - ->orWhere('t2.account')->eq($this->app->user->account) - ->orWhere('(t3.user')->eq($this->app->user->account) - ->andWhere('t3.deleted')->eq(0) - ->markRight(1) - ->orWhere("CONCAT(',', t1.whitelist, ',')")->like("%,{$this->app->user->account},%") - ->markRight(1) - ->fi() - ->orderBy($orderBy) - ->page($pager, 't1.id') - ->fetchAll('id'); + ->beginIF(!$queryAll and !$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->projects)->fi(); + if($this->cookie->involved || $involved) + { + $stmt->andWhere('t2.type')->eq('project') + ->andWhere('t1.openedBy', true)->eq($this->app->user->account) + ->orWhere('t1.PM')->eq($this->app->user->account) + ->orWhere('t2.account')->eq($this->app->user->account) + ->orWhere('(t3.user')->eq($this->app->user->account) + ->andWhere('t3.deleted')->eq(0) + ->markRight(1) + ->orWhere("CONCAT(',', t1.whitelist, ',')")->like("%,{$this->app->user->account},%") + ->markRight(1); + } + $projectList = $stmt->orderBy($orderBy)->page($pager)->fetchAll('id'); /* Determine how to display the name of the program. */ if($programTitle and $this->config->systemMode == 'ALM')