* Optimize performance of update history metriclib.
This commit is contained in:
@@ -180,10 +180,11 @@ class metric extends control
|
||||
{
|
||||
$calcObj = $calcList[$code];
|
||||
$calcObj->result = json_decode(json_encode($calc->result), true);
|
||||
$records[$code] = $this->metricZen->getRecordByCodeAndDate($code, $calcObj, $date);
|
||||
$inferenceRecord = $this->metricZen->getRecordByCodeAndDate($code, $calcObj, $date);
|
||||
if(!empty($inferenceRecord)) $records[$code] = $inferenceRecord;
|
||||
}
|
||||
}
|
||||
$this->metric->insertMetricLib($records);
|
||||
$this->metric->insertMetricLib($records, 'inference');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+20
-1
@@ -837,10 +837,11 @@ class metricModel extends model
|
||||
* Insert into metric lib.
|
||||
*
|
||||
* @param array $recordWithCode
|
||||
* @param string $calcType
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function insertMetricLib($recordWithCode)
|
||||
public function insertMetricLib($recordWithCode, $calcType = 'cron')
|
||||
{
|
||||
$this->dao->begin();
|
||||
foreach($recordWithCode as $code => $records)
|
||||
@@ -848,6 +849,8 @@ class metricModel extends model
|
||||
foreach($records as $record)
|
||||
{
|
||||
if(empty($record)) continue;
|
||||
|
||||
$record->calcType = $calcType;
|
||||
$this->dao->insert(TABLE_METRICLIB)
|
||||
->data($record)
|
||||
->exec();
|
||||
@@ -2377,4 +2380,20 @@ class metricModel extends model
|
||||
|
||||
return $this->lang->metric->noData;
|
||||
}
|
||||
|
||||
public function checkHasInferenceOfDate($code, $dateType, $date)
|
||||
{
|
||||
if($dateType == 'day' || $dateType == 'nodate') return false;
|
||||
|
||||
$date = $this->parseDateStr($date, $dateType);
|
||||
|
||||
$records = $this->dao->select('id')->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->andWhere('calcType')->eq('inference')
|
||||
->beginIF($dateType == 'year')->andWhere('year')->eq($date['year'])->fi()
|
||||
->beginIF($dateType == 'month')->andWhere('year')->eq($date['year'])->andWhere('month')->eq($date['month'])->fi()
|
||||
->beginIF($dateType == 'week')->andWhere('year')->eq($date['year'])->andWhere('week')->eq($date['week'])->fi()
|
||||
->fetch();
|
||||
return !empty($records);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,9 @@ class metricZen extends metric
|
||||
$metric = $this->metric->getByCode($code);
|
||||
$dateType = $this->metric->getDateTypeByCode($code);
|
||||
|
||||
if($dateType == 'nodate') return array();
|
||||
if($this->metric->checkHasInferenceOfDate($code, $dateType, $date)) return array();
|
||||
|
||||
$dateConfig = $this->metric->parseDateStr($date, $dateType);
|
||||
$recordCommon = $this->buildRecordCommonFields($metric->id, $code, $now, $dateConfig);
|
||||
$initRecords = $this->initMetricRecords($recordCommon, $metric->scope, "{$date} 23:59:59");
|
||||
|
||||
Reference in New Issue
Block a user