Add write cache to build log (improve speed)
This commit is contained in:
parent
e1fc4a26e3
commit
7cffc0df1e
|
@ -19,6 +19,16 @@ class BuildDBLogHandler extends AbstractProcessingHandler
|
|||
|
||||
protected $logValue;
|
||||
|
||||
/**
|
||||
* @var int last flush timestamp
|
||||
*/
|
||||
protected $flush_timestamp = 0;
|
||||
|
||||
/**
|
||||
* @var int flush delay, seconds
|
||||
*/
|
||||
protected $flush_delay = 1;
|
||||
|
||||
/**
|
||||
* @param Build $build
|
||||
* @param bool $level
|
||||
|
@ -35,6 +45,24 @@ class BuildDBLogHandler extends AbstractProcessingHandler
|
|||
$this->logValue = $build->getLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->flushData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush buffered data
|
||||
*/
|
||||
protected function flushData()
|
||||
{
|
||||
$this->build->setLog($this->logValue);
|
||||
Factory::getStore('Build')->save($this->build);
|
||||
$this->flush_timestamp = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a log entry to the build log.
|
||||
* @param array $record
|
||||
|
@ -45,8 +73,9 @@ class BuildDBLogHandler extends AbstractProcessingHandler
|
|||
$message = str_replace($this->build->currentBuildPath, '/', $message);
|
||||
|
||||
$this->logValue .= $message . PHP_EOL;
|
||||
$this->build->setLog($this->logValue);
|
||||
|
||||
Factory::getStore('Build')->save($this->build);
|
||||
if ($this->flush_timestamp < (time() - $this->flush_delay)) {
|
||||
$this->flushData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue