From 36eab43b4a0955842ef0c5f2d260b00784e01ada Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Tue, 13 Jun 2023 11:56:28 +0800 Subject: [PATCH] * Performance for welcome block. --- module/block/control.php | 1 - module/block/model.php | 90 +++++++++++-------------- module/block/view/productblock.html.php | 10 +-- 3 files changed, 43 insertions(+), 58 deletions(-) diff --git a/module/block/control.php b/module/block/control.php index 2a819f5910..54e8a57191 100755 --- a/module/block/control.php +++ b/module/block/control.php @@ -395,7 +395,6 @@ class block extends control $this->view->doneTasks = $data['doneTasks']; $this->view->bugs = $data['bugs']; $this->view->stories = $data['stories']; - $this->view->executions = $data['executions']; $this->view->delay['task'] = $data['delayTask']; $this->view->delay['bug'] = $data['delayBug']; diff --git a/module/block/model.php b/module/block/model.php index c47b36fe3d..3ef40512bd 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -164,9 +164,21 @@ class blockModel extends model */ public function getWelcomeBlockData() { + $today = date('Y-m-d'); + $data = array(); - $tasks = $this->dao->select("count(distinct t1.id) as tasks, count(distinct if(t1.status = 'done', 1, null)) as doneTasks")->from(TABLE_TASK)->alias('t1') + /* Story. */ + $data['stories'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_STORY)->alias('t1') + ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id') + ->where('t1.assignedTo')->eq($this->app->user->account) + ->andWhere('t1.deleted')->eq(0) + ->andWhere('t2.deleted')->eq(0) + ->andWhere('t1.type')->eq('story') + ->fetch('count'); + + /* Task. */ + $tasks = $this->dao->select("t1.id,t1.status,t1.deadline")->from(TABLE_TASK)->alias('t1') ->leftJoin(TABLE_PROJECT)->alias('t2')->on("t1.project = t2.id") ->leftJoin(TABLE_EXECUTION)->alias('t3')->on("t1.execution = t3.id") ->leftJoin(TABLE_TASKTEAM)->alias('t4')->on("t4.task = t1.id and t4.account = '{$this->app->user->account}'") @@ -180,65 +192,39 @@ class blockModel extends model ->beginIF(!$this->app->user->admin)->andWhere('t1.execution')->in($this->app->user->view->sprints)->fi() ->beginIF($this->config->vision)->andWhere('t1.vision')->eq($this->config->vision)->fi() ->beginIF($this->config->vision)->andWhere('t3.vision')->eq($this->config->vision)->fi() - ->fetch(); + ->fetchAll(); - $data['tasks'] = isset($tasks->tasks) ? $tasks->tasks : 0; - $data['doneTasks'] = isset($tasks->doneTasks) ? $tasks->doneTasks : 0; + $totalTasks = array(); + $delayTasks = array(); + $doneTasks = array(); + foreach($tasks as $task) + { + if($task->status == 'done') $doneTasks[$task->id] = true; + if(in_array($task->status, array('wait', 'doing')) && $task->deadline && $task->deadline < $today) $delayTasks[$task->id] = true; + $totalTasks[$task->id] = true; + } + $data['tasks'] = count($totalTasks); + $data['doneTasks'] = count($doneTasks); + $data['delayTask'] = count($delayTasks); - $data['bugs'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_BUG)->alias('t1') + /* Bug. */ + $bugs = $this->dao->select('t1.id,t1.status,t1.deadline')->from(TABLE_BUG)->alias('t1') ->leftJoin(TABLE_PRODUCT)->alias('t2')->on("t1.product = t2.id") ->where('t1.assignedTo')->eq($this->app->user->account) ->andWhere('t1.deleted')->eq(0) ->andWhere('t1.status')->ne('closed') ->andWhere('t2.deleted')->eq(0) - ->fetch('count'); - $data['stories'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_STORY)->alias('t1') - ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id') - ->where('t1.assignedTo')->eq($this->app->user->account) - ->andWhere('t1.deleted')->eq(0) - ->andWhere('t2.deleted')->eq(0) - ->andWhere('t1.type')->eq('story') - ->fetch('count'); - $data['executions'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_EXECUTION) - ->where('status')->notIN('done,closed') - ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->sprints)->fi() - ->andWhere('deleted')->eq(0) - ->fetch('count'); - $data['products'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_PRODUCT) - ->where('status')->ne('closed') - ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->products)->fi() - ->andWhere('deleted')->eq(0) - ->fetch('count'); + ->fetchAll(); - $today = date('Y-m-d'); - $data['delayTask'] = (int)$this->dao->select('count(t1.id) AS count')->from(TABLE_TASK)->alias('t1') - ->leftJoin(TABLE_PROJECT)->alias('t2')->on("t1.project = t2.id") - ->leftJoin(TABLE_EXECUTION)->alias('t3')->on("t1.execution = t3.id") - ->where('t1.assignedTo')->eq($this->app->user->account) - ->andWhere('(t2.status')->ne('suspended') - ->orWhere('t3.status')->ne('suspended') - ->markRight(1) - ->andWhere('t1.status')->in('wait,doing') - ->andWhere('t1.deadline')->notZeroDate() - ->andWhere('t1.deadline')->lt($today) - ->andWhere('t1.deleted')->eq(0) - ->andWhere('t3.deleted')->eq(0) - ->fetch('count'); - $data['delayBug'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_BUG)->alias('t1') - ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id') - ->where('t1.assignedTo')->eq($this->app->user->account) - ->andWhere('t1.status')->eq('active') - ->andWhere('t1.deadline')->notZeroDate() - ->andWhere('t1.deadline')->lt($today) - ->andWhere('t1.deleted')->eq(0) - ->andWhere('t2.deleted')->eq(0) - ->fetch('count'); - $data['delayProject'] = (int)$this->dao->select('count(*) AS count')->from(TABLE_PROJECT) - ->where('status')->in('wait,doing') - ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->sprints)->fi() - ->andWhere('end')->lt($today) - ->andWhere('deleted')->eq(0) - ->fetch('count'); + $totalBugs = array(); + $delayBugs = array(); + foreach($bugs as $bug) + { + if($bug->status == 'active' && $bug->deadline && $bug->deadline < $today) $delayBugs[$bug->id] = true; + $totalBugs[$bug->id] = true; + } + $data['bugs'] = count($totalBugs); + $data['delayBug'] = count($delayBugs); return $data; } diff --git a/module/block/view/productblock.html.php b/module/block/view/productblock.html.php index 6b0b237be1..dc60c9f634 100644 --- a/module/block/view/productblock.html.php +++ b/module/block/view/productblock.html.php @@ -42,11 +42,11 @@ id, '');?> - plans?> - releases?> - stories['active']?> - unResolved?> - + plans;?> + releases;?> + activeStories;?> + unresolvedBugs;?> +