Skip to content

Commit

Permalink
feature: collect 后清空 stmts
Browse files Browse the repository at this point in the history
  • Loading branch information
krissss committed Mar 19, 2024
1 parent fdc57c6 commit 9ff4be0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/DataCollector/PDO/PDOCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace WebmanTech\Debugbar\DataCollector\PDO;

use DebugBar\DataCollector\PDO\TraceablePDO as DebugbarTraceablePDO;
use DebugBar\DataCollector\TimeDataCollector;

class PDOCollector extends \DebugBar\DataCollector\PDO\PDOCollector
{
/**
* @inheritDoc
*/
protected function collectPDO(DebugbarTraceablePDO $pdo, TimeDataCollector $timeCollector = null, $connectionName = null)
{
$data = parent::collectPDO($pdo, $timeCollector, $connectionName);

if ($pdo instanceof TraceablePDO) {
// 清除历史记录,否则在 webman 常驻内存的情况下会有历史累计
$pdo->cleanExecutedStatements();
}

return $data;
}
}
15 changes: 15 additions & 0 deletions src/DataCollector/PDO/TraceablePDO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace WebmanTech\Debugbar\DataCollector\PDO;

class TraceablePDO extends \DebugBar\DataCollector\PDO\TraceablePDO
{
/**
* 清空历史
* @return void
*/
public function cleanExecutedStatements()
{
$this->executedStatements = [];
}
}
4 changes: 2 additions & 2 deletions src/DataCollector/ThinkPdoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace WebmanTech\Debugbar\DataCollector;

use DebugBar\DataCollector\PDO\PDOCollector;
use DebugBar\DataCollector\PDO\TraceablePDO;
use DebugBar\DataCollector\TimeDataCollector;
use think\db\PDOConnection;
use think\facade\Db;
use WebmanTech\Debugbar\DataCollector\PDO\PDOCollector;
use WebmanTech\Debugbar\DataCollector\PDO\TraceablePDO;

class ThinkPdoCollector extends PDOCollector
{
Expand Down

0 comments on commit 9ff4be0

Please sign in to comment.