From 67564c6e4b112a5de956f794c706aa9cc02fc3af Mon Sep 17 00:00:00 2001 From: tianshujie Date: Thu, 10 Aug 2023 15:52:24 +0800 Subject: [PATCH] * Optimize project overview block performance. --- db/update18.6.sql | 1 + db/zentao.sql | 21 ++++++++++++--------- module/project/model.php | 11 +++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/db/update18.6.sql b/db/update18.6.sql index af7f72e92f..f8a94f4241 100644 --- a/db/update18.6.sql +++ b/db/update18.6.sql @@ -38,6 +38,7 @@ ADD INDEX `objectType`(`objectType` ASC), ADD INDEX `status`(`status` ASC); CREATE INDEX deleted ON zt_bug (deleted); +CREATE INDEX project ON zt_bug (project); 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'; diff --git a/db/zentao.sql b/db/zentao.sql index 2767be207d..5bdebf5db3 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -353,15 +353,18 @@ CREATE TABLE IF NOT EXISTS `zt_bug` ( `deleted` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE INDEX `product` ON `zt_bug`(`product`); -CREATE INDEX `execution` ON `zt_bug`(`execution`); -CREATE INDEX `status` ON `zt_bug`(`status`); -CREATE INDEX `plan` ON `zt_bug`(`plan`); -CREATE INDEX `story` ON `zt_bug`(`story`); -CREATE INDEX `case` ON `zt_bug`(`case`); -CREATE INDEX `toStory` ON `zt_bug`(`toStory`); -CREATE INDEX `result` ON `zt_bug`(`result`); -CREATE INDEX `assignedTo` ON `zt_bug`(`assignedTo`); +CREATE INDEX `product` ON `zt_bug`(`product`); +CREATE INDEX `execution` ON `zt_bug`(`execution`); +CREATE INDEX `status` ON `zt_bug`(`status`); +CREATE INDEX `plan` ON `zt_bug`(`plan`); +CREATE INDEX `story` ON `zt_bug`(`story`); +CREATE INDEX `case` ON `zt_bug`(`case`); +CREATE INDEX `toStory` ON `zt_bug`(`toStory`); +CREATE INDEX `result` ON `zt_bug`(`result`); +CREATE INDEX `assignedTo` ON `zt_bug`(`assignedTo`); +CREATE INDEX `deleted` ON `zt_bug`(`deleted`); +CREATE INDEX `project` ON `zt_bug`(`project`); +CREATE INDEX `product_status_deleted` ON `zt_bug` (`product`,`status`,`deleted`); -- DROP TABLE IF EXISTS `zt_build`; CREATE TABLE IF NOT EXISTS `zt_build` ( diff --git a/module/project/model.php b/module/project/model.php index 9cc4326ee6..423933aaa4 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -395,12 +395,11 @@ class projectModel extends model */ public function getTotalTaskByProject($projectIdList) { - return $this->dao->select("t1.project, count(t1.id) as allTasks, count(if(t1.status = 'wait', 1, null)) as waitTasks, count(if(t1.status = 'doing', 1, null)) as doingTasks, count(if(t1.status = 'done', 1, null)) as doneTasks, count(if(t1.status = 'wait' or t1.status = 'pause' or t1.status = 'cancel', 1, null)) as leftTasks, count(if(t1.status = 'done' or t1.status = 'closed', 1, null)) as litedoneTasks")->from(TABLE_TASK)->alias('t1') - ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.execution=t2.id') - ->where('t1.project')->in($projectIdList) - ->andWhere('t1.deleted')->eq(0) - ->andWhere('t2.deleted')->eq(0) - ->groupBy('t1.project') + $executionIdList = $this->dao->select('id')->from(TABLE_EXECUTION)->where('project')->in($projectIdList)->andWhere('deleted')->eq(0)->fetchPairs(); + return $this->dao->select("project, count(id) as allTasks, count(if(status = 'wait', 1, null)) as waitTasks, count(if(status = 'doing', 1, null)) as doingTasks, count(if(status = 'done', 1, null)) as doneTasks, count(if(status = 'wait' or status = 'pause' or status = 'cancel', 1, null)) as leftTasks, count(if(status = 'done' or status = 'closed', 1, null)) as litedoneTasks")->from(TABLE_TASK) + ->where('execution')->in($executionIdList) + ->andWhere('deleted')->eq(0) + ->groupBy('project') ->fetchAll('project'); }