* Adjust for refreshStats.

This commit is contained in:
wangyidong
2023-12-22 09:33:52 +08:00
parent 7166651759
commit acc7fd5510
2 changed files with 21 additions and 34 deletions
+6 -11
View File
@@ -1797,15 +1797,14 @@ class productModel extends model
* If productStatsTime is before two weeks ago, refresh all products directly.
* Else only refresh the latest products in action table.
*/
$productActions = array();
$products = array();
$products = array();
if($updateTime < date('Y-m-d', strtotime('-14 days')) or $refreshAll)
{
$products = $this->dao->select('id')->from(TABLE_PRODUCT)->fetchPairs('id');
}
else
{
$productActions = $this->dao->select('distinct product')->from(TABLE_ACTION)
$productActions = $this->dao->select('product')->from(TABLE_ACTION)
->where('date')->ge($updateTime)
->andWhere('product')->notin(array(',0,', ',,'))
->fetchPairs('product');
@@ -1813,12 +1812,11 @@ class productModel extends model
foreach($productActions as $productAction)
{
foreach(explode(',', trim($productAction, ',')) as $product)
{
$products[$product] = $product;
}
foreach(explode(',', trim($productAction, ',')) as $product) $products[$product] = $product;
}
$products = array_filter($products);
}
if(empty($products)) return;
/* 1. Get summary and members of products to be refreshed. */
$stories = $this->dao->select('product, status, `closedReason`, count(id) AS c')
@@ -1902,10 +1900,7 @@ class productModel extends model
}
/* 2. Refresh stats to db. */
foreach($stats as $productID=> $product)
{
$this->dao->update(TABLE_PRODUCT)->data($product)->where('id')->eq($productID)->exec();
}
foreach($stats as $productID => $product) $this->dao->update(TABLE_PRODUCT)->data($product)->where('id')->eq($productID)->exec();
/* 3. Update projectStatsTime in config. */
$this->loadModel('setting')->setItem('system.common.global.productStatsTime', $now);
+15 -23
View File
@@ -1314,36 +1314,28 @@ class programModel extends model
$projects = array();
if($updateTime < date('Y-m-d', strtotime('-14 days')) or $refreshAll)
{
$projects = $this->dao->select('id,project,model,deleted')->from(TABLE_PROJECT)->fetchAll('id');
$projects = $this->dao->select('id')->from(TABLE_PROJECT)->where('type')->eq('project')->fetchPairs('id');
}
else
{
$projects = $this->dao->select('distinct t1.project,t2.model,t2.deleted')->from(TABLE_ACTION)->alias('t1')
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
->where('t1.`date`')->ge($updateTime)
->fetchAll('project');
if(empty($projects)) return;
$projects = $this->dao->select('project')->from(TABLE_ACTION)->where('`date`')->ge($updateTime)->andWhere('project')->ne(0)->fetchPairs('project');
}
if(empty($projects)) return;
$executionGroup = $this->dao->select('id,project')->from(TABLE_PROJECT)->where('project')->in($projects)->andWhere('deleted')->eq(0)->fetchGroup('project', 'id');
$summary = array();
/* 1. Execution has no tasks.*/
foreach($projects as $project)
foreach($projects as $projectID => $project)
{
$executions = $this->dao->select('id')->from(TABLE_PROJECT)->where('project')->eq($project->project)->andWhere('deleted')->eq(0)->fetchPairs();
foreach($executions as $executionID)
$executions = zget($executionGroup, $projectID, array());
foreach($executions as $executionID => $execution)
{
$taskCount = $this->dao->select('id')->from(TABLE_TASK)
->where('deleted')->eq(0)
->andWhere('execution')->eq($executionID)
->count();
if(empty($taskCount))
{
$summary[$executionID] = new stdclass();
$summary[$executionID]->totalEstimate = 0;
$summary[$executionID]->totalConsumed = 0;
$summary[$executionID]->totalLeft = 0;
$summary[$executionID]->execution = $executionID;
}
$summary[$executionID] = new stdclass();
$summary[$executionID]->totalEstimate = 0;
$summary[$executionID]->totalConsumed = 0;
$summary[$executionID]->totalLeft = 0;
$summary[$executionID]->execution = $executionID;
}
}
@@ -1352,7 +1344,7 @@ class programModel extends model
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
->where('t1.deleted')->eq(0)
->andWhere('t1.parent')->ge(0) // Ignore parent task.
->beginIF(!empty($projects))->andWhere('t1.project')->in(array_keys($projects))->fi()
->beginIF(!empty($projects))->andWhere('t1.project')->in($projects)->fi()
->fetchAll('id');
foreach($tasks as $task)
@@ -1375,7 +1367,7 @@ class programModel extends model
$teamMembers = $this->dao->select('t1.root, COUNT(1) AS members')->from(TABLE_TEAM)->alias('t1')
->leftJoin(TABLE_USER)->alias('t2')->on('t1.account=t2.account')
->where('t1.type')->eq('project')
->beginIF(!empty($projects))->andWhere('t1.root')->in(array_keys($projects))->fi()
->beginIF(!empty($projects))->andWhere('t1.root')->in($projects)->fi()
->andWhere('t2.deleted')->eq(0)
->groupBy('t1.root')
->fetchPairs('root');