Merge branch 'sql-optimization-zhangrunyu' into 'master'

SQL optimization

See merge request easycorp/zentaopms!924
This commit is contained in:
朱金勇
2021-12-20 00:47:21 +00:00
5 changed files with 49 additions and 49 deletions
+10 -10
View File
@@ -2353,13 +2353,13 @@ class bugModel extends model
public function getUnconfirmed($productIDList, $branch, $modules, $executions, $orderBy, $pager, $projectID)
{
return $this->dao->select('*')->from(TABLE_BUG)
->where('confirmed')->eq(0)
->where('product')->in($productIDList)
->andWhere('execution')->in(array_keys($executions))
->andWhere('deleted')->eq(0)
->andWhere('confirmed')->eq(0)
->beginIF($branch !== 'all')->andWhere('branch')->in($branch)->fi()
->beginIF($modules)->andWhere('module')->in($modules)->fi()
->beginIF($projectID)->andWhere('project')->eq($projectID)->fi()
->andWhere('product')->in($productIDList)
->andWhere('execution')->in(array_keys($executions))
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
@@ -2380,8 +2380,8 @@ class bugModel extends model
public function getOverdueBugs($productIDList, $branch, $modules, $executions, $orderBy, $pager, $projectID)
{
return $this->dao->select('*')->from(TABLE_BUG)
->where('execution')->in(array_keys($executions))
->andWhere('product')->in($productIDList)
->where('product')->in($productIDList)
->andWhere('execution')->in(array_keys($executions))
->beginIF($branch !== 'all')->andWhere('branch')->in($branch)->fi()
->beginIF($modules)->andWhere('module')->in($modules)->fi()
->beginIF($projectID)->andWhere('project')->eq($projectID)->fi()
@@ -2409,8 +2409,8 @@ class bugModel extends model
public function getByStatus($productIDList, $branch, $modules, $executions, $status, $orderBy, $pager, $projectID)
{
return $this->dao->select('*')->from(TABLE_BUG)
->where('execution')->in(array_keys($executions))
->andWhere('product')->in($productIDList)
->where('product')->in($productIDList)
->andWhere('execution')->in(array_keys($executions))
->beginIF($branch !== 'all')->andWhere('branch')->in($branch)->fi()
->beginIF($modules)->andWhere('module')->in($modules)->fi()
->beginIF($status == 'unclosed')->andWhere('status')->ne('closed')->fi()
@@ -3051,8 +3051,8 @@ class bugModel extends model
{
return $this->dao->select('id')
->from(TABLE_PROJECT)
->where('deleted')->eq(0)
->andWhere('type')->eq('project')
->where('type')->eq('project')
->andWhere('deleted')->eq(0)
->fetchPairs('id');
}
}
+8 -8
View File
@@ -1202,11 +1202,11 @@ class executionModel extends model
public function getIdList($projectID, $status = 'all')
{
return $this->dao->select('id')->from(TABLE_EXECUTION)
->where('deleted')->eq('0')
->where('type')->in('sprint,stage')
->andWhere('deleted')->eq('0')
->beginIF($projectID)->andWhere('project')->eq($projectID)->fi()
->beginIF($status == 'undone')->andWhere('status')->notIN('done,closed')->fi()
->beginIF($status != 'all' and $status != 'undone')->andWhere('status')->in($status)->fi()
->andWhere('type')->in('sprint,stage')
->fetchPairs('id', 'id');
}
@@ -1228,12 +1228,12 @@ class executionModel extends model
$orderBy = (isset($project->model) and $project->model == 'waterfall') ? 'begin_asc,id_asc' : 'begin_desc,id_desc';
$executions = $this->dao->select('*')->from(TABLE_EXECUTION)
->where('deleted')->eq('0')
->where('type')->in('stage,sprint')
->andWhere('deleted')->eq('0')
->beginIF($projectID)->andWhere('project')->eq((int)$projectID)->fi()
->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->sprints)->fi()
->beginIF($status == 'undone')->andWhere('status')->notIN('done,closed')->fi()
->beginIF($status != 'all' and $status != 'undone')->andWhere('status')->in($status)->fi()
->andWhere('type')->in('stage,sprint')
->orderBy($orderBy)
->beginIF($limit)->limit($limit)->fi()
->fetchAll('id');
@@ -2703,7 +2703,7 @@ class executionModel extends model
$burns = array();
$executions = $this->dao->select('id, code')->from(TABLE_EXECUTION)
->where("end")->ge($today)
->where('end')->ge($today)
->andWhere('type')->ne('ops')
->andWhere('status')->notin('done,closed,suspended')
->fetchPairs();
@@ -2717,7 +2717,7 @@ class executionModel extends model
->andWhere('status')->ne('cancel')
->groupBy('execution')
->fetchAll('execution');
$closedLefts = $this->dao->select("execution, sum(`left`) AS `left`")->from(TABLE_TASK)
$closedLefts = $this->dao->select('execution, sum(`left`) AS `left`')->from(TABLE_TASK)
->where('execution')->in(array_keys($executions))
->andWhere('deleted')->eq('0')
->andWhere('parent')->ge('0')
@@ -2774,7 +2774,7 @@ class executionModel extends model
public function fixFirst($executionID)
{
$execution = $this->getById($executionID);
$burn = $this->dao->select('*')->from(TABLE_BURN)->where('execution')->eq($executionID)->andWhere('task')->eq(0)->andWhere('date')->eq($execution->begin)->fetch();
$burn = $this->dao->select('*')->from(TABLE_BURN)->where('execution')->eq($executionID)->andWhere('date')->eq($execution->begin)->andWhere('task')->eq(0)->fetch();
$withLeft = $this->post->withLeft ? $this->post->withLeft : 0;
$data = fixer::input('post')
@@ -3080,7 +3080,7 @@ class executionModel extends model
*/
public function getTotalEstimate($executionID)
{
$estimate = $this->dao->select('SUM(estimate) as estimate')->from(TABLE_TASK)->where('deleted')->eq('0')->andWhere('execution')->eq($executionID)->fetch('estimate');
$estimate = $this->dao->select('SUM(estimate) as estimate')->from(TABLE_TASK)->where('execution')->eq($executionID)->andWhere('deleted')->eq('0')->fetch('estimate');
return round($estimate);
}
+19 -19
View File
@@ -1448,10 +1448,10 @@ class productModel extends model
}
$plans = $this->dao->select('count(*) AS count')->from(TABLE_PRODUCTPLAN)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->andWhere('end')->gt(helper::now())->fetch();
$builds = $this->dao->select('count(*) AS count')->from(TABLE_BUILD)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch();
$cases = $this->dao->select('count(*) AS count')->from(TABLE_CASE)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch();
$bugs = $this->dao->select('count(*) AS count')->from(TABLE_BUG)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch();
$docs = $this->dao->select('count(*) AS count')->from(TABLE_DOC)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch();
$builds = $this->dao->select('count(*) AS count')->from(TABLE_BUILD)->where('product')->eq($productID)->andWhere('deleted')->eq(0)->fetch();
$cases = $this->dao->select('count(*) AS count')->from(TABLE_CASE)->where('product')->eq($productID)->andWhere('deleted')->eq(0)->fetch();
$bugs = $this->dao->select('count(*) AS count')->from(TABLE_BUG)->where('product')->eq($productID)->andWhere('deleted')->eq(0)->fetch();
$docs = $this->dao->select('count(*) AS count')->from(TABLE_DOC)->where('product')->eq($productID)->andWhere('deleted')->eq(0)->fetch();
$releases = $this->dao->select('count(*) AS count')->from(TABLE_RELEASE)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch();
$projects = $this->dao->select('count("t1.*") AS count')->from(TABLE_PROJECTPRODUCT)->alias('t1')
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
@@ -1477,7 +1477,7 @@ class productModel extends model
$product->bugs = $bugs ? $bugs->count : 0;
$product->docs = $docs ? $docs->count : 0;
$closedTotal = $this->dao->select('count(id) AS count')->from(TABLE_STORY)->where('deleted')->eq(0)->andWhere('status')->eq('closed')->andWhere('product')->eq($productID)->fetch('count');
$closedTotal = $this->dao->select('count(id) AS count')->from(TABLE_STORY)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->andWhere('status')->eq('closed')->fetch('count');
$allTotal = $this->dao->select('count(id) AS count')->from(TABLE_STORY)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch('count');
$product->progress = empty($closedTotal) ? 0 : round($closedTotal / $allTotal * 100, 1);
@@ -1588,33 +1588,33 @@ class productModel extends model
$bugs = $this->dao->select('product,count(*) AS conut')
->from(TABLE_BUG)
->where('deleted')->eq(0)
->andWhere('product')->in($productKeys)
->where('product')->in($productKeys)
->andWhere('deleted')->eq(0)
->groupBy('product')
->fetchPairs();
$unResolved = $this->dao->select('product,count(*) AS count')
->from(TABLE_BUG)
->where('deleted')->eq(0)
->andwhere('status')->eq('active')
->where('status')->eq('active')
->andWhere('product')->in($productKeys)
->andWhere('deleted')->eq(0)
->groupBy('product')
->fetchPairs();
$fixedBugs = $this->dao->select('product,count(*) AS count')
->from(TABLE_BUG)
->where('deleted')->eq(0)
->andwhere('status')->eq('closed')
->where('status')->eq('closed')
->andWhere('product')->in($productKeys)
->andWhere('deleted')->eq(0)
->andWhere('resolution')->eq('fixed')
->groupBy('product')
->fetchPairs();
$closedBugs = $this->dao->select('product,count(*) AS count')
->from(TABLE_BUG)
->where('deleted')->eq(0)
->andwhere('status')->eq('closed')
->where('status')->eq('closed')
->andWhere('product')->in($productKeys)
->andWhere('deleted')->eq(0)
->groupBy('product')
->fetchPairs();
@@ -1622,17 +1622,17 @@ class productModel extends model
$weekDate = date::getThisWeek();
$thisWeekBugs = $this->dao->select('product,count(*) AS count')
->from(TABLE_BUG)
->where('deleted')->eq(0)
->andWhere('openedDate')->between($weekDate['begin'], $weekDate['end'])
->where('openedDate')->between($weekDate['begin'], $weekDate['end'])
->andWhere('product')->in($productKeys)
->andWhere('deleted')->eq(0)
->groupBy('product')
->fetchPairs();
$assignToNull = $this->dao->select('product,count(*) AS count')
->from(TABLE_BUG)
->where('deleted')->eq(0)
->andwhere('assignedTo')->eq('')
->where('assignedTo')->eq('')
->andWhere('product')->in($productKeys)
->andWhere('deleted')->eq(0)
->groupBy('product')
->fetchPairs();
@@ -1741,8 +1741,8 @@ class productModel extends model
$hourList = $this->loadModel('project')->computerProgress($latestExecutionList);
$releaseList = $this->dao->select('id,product,name,marker')->from(TABLE_RELEASE)
->where('product')->in(array_keys($productList))
->andWhere('deleted')->eq('0')
->where('deleted')->eq('0')
->andWhere('product')->in(array_keys($productList))
->andWhere('status')->eq('normal')
->fetchGroup('product', 'id');
+11 -11
View File
@@ -170,10 +170,10 @@ class storyModel extends model
public function getRequierements($productID)
{
return $this->dao->select('id,title')->from(TABLE_STORY)
->where('deleted')->eq(0)
->andWhere('status')->notIN('draft,closed')
->andWhere('product')->eq($productID)
->andWhere('type')->eq('requirement')
->andWhere('status')->notIN('draft,closed')
->where('deleted')->eq(0)
->fetchPairs();
}
@@ -1186,7 +1186,7 @@ class storyModel extends model
$story->version = $story->title == $oldStory->title ? $oldStory->version : $oldStory->version + 1;
if($story->stage != $oldStory->stage) $story->stagedBy = (strpos('tested|verified|released|closed', $story->stage) !== false) ? $this->app->user->account : '';
if($story->title != $oldStory->title and $story->status != draft) $story->status = 'changed';
if($story->title != $oldStory->title and $story->status != 'draft') $story->status = 'changed';
if($story->closedBy != false and $oldStory->closedDate == '') $story->closedDate = $now;
if($story->closedReason != false and $oldStory->closedDate == '') $story->closedDate = $now;
if($story->closedBy != false or $story->closedReason != false) $story->status = 'closed';
@@ -2029,11 +2029,11 @@ class storyModel extends model
/* Search related tasks. */
$tasks = $this->dao->select('type,execution,status')->from(TABLE_TASK)
->where('execution')->in(array_keys($executions))
->andWhere('story')->eq($storyID)
->andWhere('type')->in('devel,test')
->andWhere('story')->eq($storyID)
->andWhere('deleted')->eq(0)
->andWhere('status')->ne('cancel')
->andWhere('closedReason')->ne('cancel')
->andWhere('deleted')->eq(0)
->fetchGroup('type');
/* No tasks, then the stage is projected. */
@@ -2223,8 +2223,8 @@ class storyModel extends model
->beginIF(!empty($moduleIdList))->andWhere('module')->in($moduleIdList)->fi()
->beginIF(!empty($excludeStories))->andWhere('id')->notIN($excludeStories)->fi()
->beginIF($status and $status != 'all')->andWhere('status')->in($status)->fi()
->andWhere('deleted')->eq(0)
->andWhere('type')->eq($type)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
@@ -2256,8 +2256,8 @@ class storyModel extends model
->beginIF($branch !== 'all')->andWhere('t1.branch')->in($branch)->fi()
->beginIF(!$hasParent)->andWhere('t1.parent')->ge(0)->fi()
->beginIF($status and $status != 'all')->andWhere('t1.status')->in($status)->fi()
->andWhere('t1.deleted')->eq(0)
->andWhere('t1.type')->eq($storyType)
->andWhere('t1.deleted')->eq(0)
->orderBy($order)
->fetchAll();
if(!$stories) return array();
@@ -2381,8 +2381,8 @@ class storyModel extends model
if(!$this->loadModel('common')->checkField(TABLE_STORY, $fieldName)) return array();
$stories = $this->dao->select('*')->from(TABLE_STORY)
->where('product')->in($productID)
->andWhere('deleted')->eq(0)
->andWhere('type')->eq($type)
->andWhere('deleted')->eq(0)
->beginIF($branch != 'all')->andWhere("branch")->eq($branch)->fi()
->beginIF($modules)->andWhere("module")->in($modules)->fi()
->beginIF($operator == 'equal')->andWhere($fieldName)->eq($fieldValue)->fi()
@@ -2790,9 +2790,9 @@ class storyModel extends model
->andWhere('parent')->le(0)
->andWhere('type')->eq('story')
->andWhere('stage')->eq('wait')
->andWhere('plan')->in('0,')
->andWhere('status')->notin('closed,draft')
->andWhere('product')->eq($productID)
->andWhere('plan')->in('0,')
->beginIF($append)->orWhere('id')->in($append)->fi()
->fetchPairs();
return array(0 => '') + $stories ;
@@ -3507,10 +3507,10 @@ class storyModel extends model
if($type == 'requirement')
{
$relations = $this->dao->select('DISTINCT AID, BID')->from(TABLE_RELATION)
->where('AID')->in(array_keys($stories))
->andWhere('AType')->eq('requirement')
->where('AType')->eq('requirement')
->andWhere('BType')->eq('story')
->andWhere('relation')->eq('subdivideinto')
->andWhere('AID')->in(array_keys($stories))
->fetchAll();
$group = array();
+1 -1
View File
@@ -99,8 +99,8 @@ class userModel extends model
$users = $this->dao->select($fields)->from(TABLE_USER)
->where('1')
->beginIF(strpos($params, 'all') === false)->andWhere('type')->eq($type)->fi()
->beginIF(strpos($params, 'nodeleted') !== false or empty($this->config->user->showDeleted))->andWhere('deleted')->eq('0')->fi()
->beginIF(strpos($params, 'all') === false)->andWhere('type')->eq($type)->fi()
->beginIF($accounts)->andWhere('account')->in($accounts)->fi()
->orderBy($orderBy)
->beginIF($maxCount)->limit($maxCount)->fi()